我有以下刺痛
2014-06-03T07:00:00.000Z
我希望像
一样快速转换它strtotime("Y-m-d h:i",2014-06-03T07:00:00.000Z");
但这不起作用......我可以做些什么来轻松转换上述格式的时间?
答案 0 :(得分:3)
您错误地使用 strtotime() - 它返回时间戳,而不是格式化日期。您需要将其与 date() 结合使用,它将根据给定的时间戳返回格式化日期:
$date = "2014-06-03T07:00:00.000Z";
echo date("Y-m-d h:i", strtotime($date));
答案 1 :(得分:0)
要回答你的问题,你想要的是:
date("Y-m-d h:i", strtotime("2014-06-03T07:00:00.000Z"));
但是,我要提一下,您的示例也是格式错误的 - 您在输入字符串的开头缺少引号。
strtotime("Y-m-d h:i",2014-06-03T07:00:00.000Z");
^missing a " right there
现在让我告诉你问题是什么:
strtotime
函数可选地期望相对日期(如所描述的here),例如"+2 days"
和时间,并返回UNIX时间戳(可能看起来像{{ 1}})。 1401778800
不会为您格式化该日期。因此,您使用strtotime
来获取时间戳。
获得时间戳后,您可以使用strtotime
函数对其进行格式化,该函数采用格式字符串和时间戳。
为了在PHP中将一种日期格式转换为另一种日期格式,您需要同时使用date
和date
来创建时间戳,然后对其进行格式化。