gpt4 book ai didi

mysql - 如何将 "2017-03-24T11:12:04+08:00"这样的时间字符串转换为unix时间戳

转载 作者:行者123 更新时间:2023-11-29 17:51:36 24 4
gpt4 key购买 nike

我知道 unix_timestamp 可以做到这一点,如下所示:

SELECT unix_timestamp('2017-03-24T11:12:04+08:00');

但是,当设置 time_zone 时:

SET time_zone='+0:00';   // the timestamp will be: 1490353924

set time_zone='+8:00';   // the timestamp will be: 1490325124

那么,如何获取始终为 1490353924 的时间戳?

就像MySQL数据类型TIMESTAMP一样:无论time_zone是什么,秒数都不会改变,总是从1970-01-01:00:00:00 utc +0:00开始。

select unix_timestamp(time_stamp_column) from `TABLE_TEST`;  // time_stamp_column is a column of talbe TABLE_TEST, and it's type is TIMESTAMP

最佳答案

你可以试试这个代码。

set @@global.time_zone = '+00:00';

set @@global.time_zone = '+8:00';

关于mysql - 如何将 "2017-03-24T11:12:04+08:00"这样的时间字符串转换为unix时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49277349/

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