SQLite中的UTC时间错误
UTC time wrong in SQLite
我的 Centos 7.6 服务器实际位于德国,但配置为向我(在伦敦)显示正确的本地时间和 UTC 时间。
$ date
Tue Jul 16 08:31:51 BST 2019
$ date -u
Tue Jul 16 07:31:55 UTC 2019
但是在 SQLite 数据库中,情况就不对了。
$ !sql
sqlite3 apollo.db
SQLite version 3.7.17 2013-05-20 00:56:22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> select datetime('now');
2019-07-16 07:32:48
sqlite> select datetime('now', 'localtime');
2019-07-16 08:32:53
sqlite> select datetime('now', 'utc');
2019-07-16 06:32:58
它正确显示当地时间,但 UTC 时间晚了一个小时。有没有我可以调整的配置设置来解决这个问题?
更新:好的。更仔细地阅读 the documentation 之后,我似乎误会了,这种行为是 a) 正确的和 b) 预期的。 select datetime('now')
是获取 UTC 时间的正确方法。所以现在我对 select datetime('now', 'utc')
正在做什么感到有点困惑(可能没什么用)。
Update: Ok. Having read the documentation a bit more carefully, it seems I was misunderstanding and this behaviour is a) correct and b) expected. select datetime('now') is the correct way to get UTC time. So now I'm just a bit confused as to what select datetime('now', 'utc') is doing (probably nothing useful).
示例前的最后一段解释说:-
The "utc" modifier is the opposite of "localtime".
"utc" assumes that the string to its left is in the local timezone and adjusts that string to be in UTC.
If the prior string is not in localtime, then the result of "utc" is undefined.
我的 Centos 7.6 服务器实际位于德国,但配置为向我(在伦敦)显示正确的本地时间和 UTC 时间。
$ date
Tue Jul 16 08:31:51 BST 2019
$ date -u
Tue Jul 16 07:31:55 UTC 2019
但是在 SQLite 数据库中,情况就不对了。
$ !sql
sqlite3 apollo.db
SQLite version 3.7.17 2013-05-20 00:56:22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> select datetime('now');
2019-07-16 07:32:48
sqlite> select datetime('now', 'localtime');
2019-07-16 08:32:53
sqlite> select datetime('now', 'utc');
2019-07-16 06:32:58
它正确显示当地时间,但 UTC 时间晚了一个小时。有没有我可以调整的配置设置来解决这个问题?
更新:好的。更仔细地阅读 the documentation 之后,我似乎误会了,这种行为是 a) 正确的和 b) 预期的。 select datetime('now')
是获取 UTC 时间的正确方法。所以现在我对 select datetime('now', 'utc')
正在做什么感到有点困惑(可能没什么用)。
Update: Ok. Having read the documentation a bit more carefully, it seems I was misunderstanding and this behaviour is a) correct and b) expected. select datetime('now') is the correct way to get UTC time. So now I'm just a bit confused as to what select datetime('now', 'utc') is doing (probably nothing useful).
示例前的最后一段解释说:-
The "utc" modifier is the opposite of "localtime".
"utc" assumes that the string to its left is in the local timezone and adjusts that string to be in UTC.
If the prior string is not in localtime, then the result of "utc" is undefined.