2017-01-03 79 views
1

如何在PHP中将2017-03-01转换为March 1st 2017格式。将2017-03-01转换为2017年3月1日格式inPHP

$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

使用'的strtotime()''到$ mark_entry_last_date',检查[这里](http://ideone.com/xcBEdU) – Fabio

+2

[Strtotime()的可能重复不适用于dd/mm/YYYY格式](http://stackoverflow.com/questions/2891937/strtotime-doesnt-work-with-dd-mm-yyyy-format) –

回答

3

date函数期望第二个参数是时间戳(整数)不是字符串,所以你需要使用strtotime

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

还需要逃避usup标签。由于u是用于显示微秒的格式。

相关问题