2017-01-03 77 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是用於顯示微秒的格式。

相關問題