如何使用PHP更改日期格式?我使用了以下代码,但它将日期输入字段值显示为m-d-Y。为什么要改变格式?
$effectivedate = date('M-d-Y', strtotime($empCompensationdata-effective_date));
$effective_date = date('Y-m-d', strtotime($empCompensationdata-effective_date));
$("#effective_date").val($effectivedate);
$('#effective_date').attr('data-value', $effective_date);
答案 0 :(得分:0)
The reason the value is displayed as M-d-Y is because that's what you're assigning to it with the val() method:
$effectivedate = date('M-d-Y', strtotime($empCompensationdata->effective_date));
$effective_date = date('Y-m-d', strtotime($empCompensationdata->effective_date));
$("#effective_date").val($effectivedate); //This variable contains "M-d-Y"
$('#effective_date').attr('data-value', $effective_date);
So if you want to have Y-m-d, just change the assigning variable:
$("#effective_date").val($effective_date); //This variable contains "Y-m-d"