将2017-03-01转换为2017年3月1日的格式inPHP

时间:2017-01-03 06:37:56

标签: php codeigniter

如何在PHP中将2017-03-01转换为March 1st 2017格式。

 $mark_entry_last_date=$exam_dates['last_date'];

 echo date('M j<\sup>S</\sup> Y', $mark_entry_last_date);

以上代码仅输出当前日期,但我需要$ mark_entry_last_date的日期值。如何使用转义字符获取2017年3月1日给定日期的结果。 ?

2 个答案:

答案 0 :(得分:4)

date函数需要第二个参数为时间戳(整数)而不是字符串,因此您需要使用strtotime

echo date('M j<\s\up>S</\s\up> Y', strtotime($mark_entry_last_date));

此外,您需要为u代码转义sup。由于u是显示微秒的格式。

答案 1 :(得分:1)

尝试不使用标记并使用strtotime()

echo date("F jS Y", strtotime("2017-03-01"));  
// output March 1st 2017

了解更多http://php.net/manual/en/function.strtotime.php

相关问题