[英]What datatype should I use for “2020-04-11T19:54:00.0000000Z” in a MySQL SQL database?
What time format is 2020-04-11T19:54:00.0000000Z
?什么时间格式是
2020-04-11T19:54:00.0000000Z
? Should it be entered in a SQL database as DATE
, DATETIME
, TIMESTAMP
, TIME
, or YEAR
?是否应该在 SQL 数据库中输入
DATE
、 DATETIME
、 TIMESTAMP
、 TIME
或YEAR
?
This is ISO-8601 .这是ISO-8601 。 The format includes date, time with possible precision of fractions of second, and time zone information.
格式包括日期、可能精确到秒的时间和时区信息。
Basically you should use either DATETIME, or convert to UNSIGNED INT, depending on what you prefer.基本上你应该使用 DATETIME,或者转换为 UNSIGNED INT,这取决于你喜欢什么。
The devil is in details.魔鬼在细节中。 If all the values you receive end with Z, then you can assume you receive datetime in UTC.
如果您收到的所有值都以 Z 结尾,那么您可以假设您收到的日期时间为 UTC。 Just use DATETIME and take care your MySQL server is set up to UTC timezone.
只需使用 DATETIME 并注意您的 MySQL 服务器设置为 UTC 时区。
Do you need to store timezone name for later retrieval?您是否需要存储时区名称以供以后检索? In this case, you will need to parse input value into two fields.
在这种情况下,您需要将输入值解析为两个字段。 One field to keep datetime in UTC format and second to store time zone value (MySQL's datetime field type does not store time zone value).
一个字段将日期时间保持为 UTC 格式,第二个字段用于存储时区值(MySQL 的日期时间字段类型不存储时区值)。 Also take care of converting input values to UTC.
还要注意将输入值转换为 UTC。 If you're using MySQL version 8.0.19 or later, it can do that for you .
如果您使用的是 MySQL 版本 8.0.19 或更高版本,它可以为您做到这一点。
Do take care to set your MySQL server time zone variable to UTC.请注意将 MySQL 服务器时区变量设置为 UTC。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.