gpt4 book ai didi

php - 为什么 SQL 时间戳不是 UTC?

转载 作者:行者123 更新时间:2023-11-29 00:04:34 25 4
gpt4 key购买 nike

我像这样从 SQL 中选择当前日期:

foreach ($dbh->query('SELECT CURRENT_TIMESTAMP as `now`;') as $row) {
echo $row['now'];
}

输出是这样的:2015-01-24 12:46:45。这是我电脑上的时间,GMT-0500 (EST)。但是,我认为 SQL 时间戳应该总是在 UTC 中吗?为什么这个时间戳不是 UTC?

最佳答案

没有规定必须使用 UTC,相反请参阅文档(强调我的):

http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_current-timestamp

Returns the current time as a value in 'HH:MM:SS' or HHMMSS.uuuuuu format, depending on whether the function is used in a string or numeric context. The value is expressed in the current time zone.

有一个 UTC_TIMESTAMP() 函数可以获取 UTC 时间戳,您也可以使用 UNIX_TIMESTAMP() 函数(但这会给您不同的数据类型).

关于php - 为什么 SQL 时间戳不是 UTC?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28128879/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com