Convert Javascript time to MySQL format using PHP

后端 未结 4 1720
你的背包
你的背包 2021-01-22 01:01

How can I convert a js Date (like this Sun Jul 13 2014 07:00:00 GMT+0200 (EET)) to MySQL format (like this 2014-07-13 07:00:00) using php ?

4条回答
  •  深忆病人
    2021-01-22 01:30

    I will try to enhance @akuzminsky answer a little. Since date_parse is using strtotime internally to parse the date, you can use it directly and make your code more flexible.

    There is a small drawback since you need to set the time zone in order to use date correctly and avoid php warning. I am setting it to Europe/Athens but you can find here all available codes.

    date_default_timezone_set("Europe/Athens");
    
    $unixTimeStamp = strtotime("Sun Jul 13 2014 07:00:00 GMT+0200 (EET)");
    $newFormat = date('Y-m-d H:i:s', $unixTimeStamp );
    
    echo $newFormat;
    

提交回复
热议问题