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

天大地大妈咪最大 提交于 2019-12-04 04:27:53

问题


How to change format of date string using PHP?

From: 06/16/2010
To: 2010-06-16


回答1:


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

Using the strtotime function.




回答2:


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




回答3:


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



来源:https://stackoverflow.com/questions/3074525/how-to-change-date-format-from-dd-mm-yyyy-to-yyyy-mm-dd

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!