开发者

How to change date format from DD/MM/YYYY to YYYY-MM-DD? [duplicate]

This question already has answers here: 开发者_JAVA技巧 How to reformat date in PHP? (9 answers) Closed 6 years ago.

How to change format of date string using PHP?

From: 06/16/2010

To: 2010-06-16


$date = "06/16/2010";
echo date('Y-m-d', strtotime($date)); // outputs 2010-06-16

Using the strtotime function.


You should use \DateTime and get rid of strings as soon as possible:

$date = DateTime::createFromFormat('m/d/Y', '06/16/2010'); // \DateTime object
echo $date->format('Y-m-d'); // 2010-06-16

See more:
http://php.net/manual/en/datetime.createfromformat.php


php -r 'echo date("Y-m-d", strtotime("06/16/2010"));'

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜