简体   繁体   English

将英国日期转换为UTC

[英]Converting UK date to UTC

I have a table called pm_msg with a time column and the following values: 我有一个名为pm_msg的表,其中带有一个时间列和以下值:

07-02-2013 18:11:00
27-01-2013 16:02:44
28-01-2013 10:30:26
30-01-2013 13:30:06

I would like to convert them to Unix timestamp while running an PDO SQL query. 我想在运行PDO SQL查询时将它们转换为Unix时间戳。 This is what I've done so far, but it seems to return an error. 到目前为止,这是我所做的,但似乎返回了错误。 How should I go about doing it? 我应该怎么做呢?

$sql = "SELECT * from pm_msg ORDER BY (strtotime(time)) ASC;";

strtotime does not exist in MySQL, you want the UNIX_TIMESTAMP function: strtotime在MySQL中不存在,您需要UNIX_TIMESTAMP函数:

$sql = "SELECT * from pm_msg ORDER BY (UNIX_TIMESTAMP(time)) ASC;";

But - you don't need to convert it to a UNIX timestamp just to sort it. 但是-您不必仅将其转换为UNIX时间戳即可。 Sorting works correctly on dates? 在日期上排序是否正确? Maybe you intend to add the UNIX_TIMESTAMP to the SELECT portion? 也许您打算将UNIX_TIMESTAMP添加到SELECT部分?

UTC is more or less the same as GMT - does not take into account of DST. UTC与GMT大致相同-不考虑DST。

So in spring and autumn you need to take that into account. 因此,在春季和秋季,您需要考虑到这一点。

But to convert a date/time into unixtime using SQL see STR_TO_DATE or UNIXTIMESTAMP 但是要使用SQL将日期/时间转换为unixtime,请参见STR_TO_DATEUNIXTIMESTAMP

如果您现在正在使用类似varchar的方法 ,将时间列设置为datetime会更容易。

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

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