How to format datetime most easily in PHP?

后端 未结 4 1827
不思量自难忘°
不思量自难忘° 2020-12-18 04:20

To change 2009-12-09 13:32:15 to 09/12/2009

4条回答
  •  孤城傲影
    2020-12-18 05:16

     $long_date = '2009-12-09 13:32:15';
    
     $epoch_date = strtotime($long_date);
    
     $short_date = date('m/d/Y', $epoch_date);
    

    The above is not the shortest way of doing it, but having the long date as an epoch timestamp ensures that you can reuse the original long date to get other date format outputs, like if you wanted to go back and have just the time somewhere else.

提交回复
热议问题