在mysql中存储UTC时间戳

在mysql中存储UTC时间戳,mysql,sqldatatypes,Mysql,Sqldatatypes,我想在我的mysql数据库中存储UTC时间戳。将其存储为INT的数据类型就足够了吗?当前,时间戳的长度为10位,并且INTdatatype的最大限制值为有符号2147483647。我对mysql非常陌生,所以我不确定通常做什么。是的,可以将UTC时间存储为int 11 您需要使用from_unixtime()将其转换回sql查询中的datatime格式。是的,您可以将UTC时间存储为int 11 您需要使用from_unixtime()将其转换回sql查询中的datatime格式。只需对时间戳使

我想在我的mysql数据库中存储UTC时间戳。将其存储为
INT
的数据类型就足够了吗?当前,时间戳的长度为10位,并且
INT
datatype的最大限制值为有符号2147483647。我对mysql非常陌生,所以我不确定通常做什么。

是的,可以将UTC时间存储为int 11


您需要使用from_unixtime()将其转换回sql查询中的datatime格式。

是的,您可以将UTC时间存储为int 11


您需要使用from_unixtime()将其转换回sql查询中的datatime格式。

只需对时间戳使用内置数据类型,如下所示:

create table test (id int, ts timestamp null default current_timestamp);
insert into test (id) values (1), (2), (3);

select * from test;

Result: 
| id |                          ts |
|----|-----------------------------|
|  1 | September, 14 2015 02:48:59 |
|  2 | September, 14 2015 02:48:59 |
|  3 | September, 14 2015 02:48:59 |

通过这种方式,您无需进行特定的转换,您可以使用人类可读的日期查询信息。

只需使用内置的数据类型作为时间戳,如下所示:

create table test (id int, ts timestamp null default current_timestamp);
insert into test (id) values (1), (2), (3);

select * from test;

Result: 
| id |                          ts |
|----|-----------------------------|
|  1 | September, 14 2015 02:48:59 |
|  2 | September, 14 2015 02:48:59 |
|  3 | September, 14 2015 02:48:59 |

通过这种方式,您无需进行特定的转换,并且可以使用人类可读的日期查询信息。

为什么您认为应该将时间戳存储为整数,为什么不将其存储为时间戳?如果使用
时间戳
数据类型会怎么样?如果其中一个答案对您有所帮助,您是否介意将其标记为一个答案来结束此问题?谢谢,@liondancer为什么您觉得应该将时间戳存储为整数?为什么不将其存储为时间戳?如果您使用
timestamp
数据类型怎么办?如果其中一个答案对您有所帮助,您是否介意将其标记为一个答案来结束此问题?谢谢你,@liondacher直到2038年的某个时候。你不应该害怕2038年。在2037年,“他们”肯定会为此发挥一些魔力。直到2038年的某个时候。我们不应该害怕2038年。到2037年,“他们”肯定会为此施点魔法。