我正在尝试获得一个字符串的完整日期,以便03-30-1986将在1986年3月30日结束。
我尝试过以下代码。
$date = 03.30.1986
$mydate = strtoTime($date);
$printdate = date('m-d-Y', $mydate);
我使用echo来查看$ printdate的结果,但事实证明它的值为null。想法?
答案 0 :(得分:1)
$date = '03.30.1986';
$mydate = strtoTime($date);
echo $printdate = date('F d, Y', $mydate);
这是工作只是添加引用...
Result :March 31, 1969
答案 1 :(得分:0)
我的想法:
strtotime()
需要一个字符串:$date = "03.30.1986"
(请注意函数名称的str
部分);
:$date = "03.30.1986";
"F d, Y"
所以你的代码变成了:
$date = "03.30.1986";
$mydate = strtoTime($date);
$printdate = date('F d, Y', $mydate);
答案 2 :(得分:0)
你的第一行有几个错误(缺少引号,分号),strtotime无法解析该日期格式,并且你使用了错误的格式来获得所需的输出。这应该有效:
$date = '03.30.1986';
$parts = explode('.', $date);
$mydate = mktime(0, 0, 0, $parts[0], $parts[1], $parts[2]);
$printdate = date('F d, Y', $mydate);
答案 3 :(得分:0)
$date = '03.30.1986';
$temp = explode('.',$date);
$date = date("m.d.Y", mktime(0, 0, 0, $temp[0], $temp[1],$temp[2]));
echo $date;
答案 4 :(得分:0)
php假设它是欧洲日期格式。有关详情,请参阅here
Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed.