简体   繁体   English

将“ 2011-12-20,3:18PM EST”插入MySQL时间戳列

[英]Inserting '2011-12-20, 3:18PM EST' into MySQL Timestamp Column

I am trying to insert timestamps in the form of 2011-12-20, 3:18PM EST into a TIMESTAMP column in a MySQL table. 我正在尝试将2011-12-20, 3:18PM EST的形式插入MySQL表的TIMESTAMP列中。

Problem: Inserting the string 2011-12-20, 3:18PM EST directly into the table gets me 2011-12-20 03:18:00 which is in AM! 问题:将字符串2011-12-20, 3:18PM EST直接插入表中会得到我在2011-12-20 03:18:00上午的信息! (Took me very long to discover this!!) (花了我很长时间才发现这一点!)

Now when I tried the following, I get a PHP error... 现在,当我尝试以下操作时,出现PHP错误...

$time = '2011-12-20,  3:18PM EST';

echo date( 'Y-m-d H:i:s', $time);

I also tried inserting the output of strtotime('2011-12-20, 3:18PM EST') into the MySQL table, which just gets me 000-00-00 00:00:00 . 我还尝试将strtotime('2011-12-20, 3:18PM EST')的输出插入MySQL表,这使我得到000-00-00 00:00:00

Question: Which is the correct way to insert the string like 2011-12-20, 3:18PM EST into the TIMESTAMP column of the table? 问题:2011-12-20, 3:18PM EST等字符串2011-12-20, 3:18PM EST插入表的TIMESTAMP列中的正确方法是什么? I want 2011-12-20 15:18:00 to end up in that column. 我希望2011-12-20 15:18:00结束该列。

Strip the 'EST' part: 去除“ EST”部分:

echo date("Y-m-d H:i:s", strtotime('2011-12-20, 3:18PM'));

You could do that with substr () or str_replace () 您可以使用substr ()或str_replace ()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM