Convert a Javascript Date format to desired PHP format

后端 未结 3 607
情深已故
情深已故 2020-12-18 23:10

How can we convert Wed Jun 09 2010 which is returns from a javascript function and get in a php script.I need to convert this date format to 2010-06-09.Thanks

3条回答
  •  没有蜡笔的小新
    2020-12-18 23:55

    Or with DateTime:

    $date = new DateTime('Wed Jun 09 2010');
    echo $date->format('Y-m-d');
    

    The date format you can input to strtotime(), DateTime and date_create() are explained in the PHP manual. If you need more control over the input format and have PHP5.3, you can use:

    $date = DateTime::createFromFormat('D M m Y', 'Wed Jun 09 2010');
    echo $date->format('Y-m-d');
    

提交回复
热议问题