将 UTC 时间字符串转换为 Unix 时间
在我的数据库中,我将时间存储为 BIGINT UTC 值。
在我的测试数据 SQL 转储中,我希望查看 UTC 时间以提高可读性。然而,MySQL unix_timestamp 函数需要本地时区的时间,这是我试图避免的。
我环顾四周,发现将 UTC 时间字符串转换为 unix 时间戳的唯一方法是使用以下表达式:
SELECT unix_timestamp(CONVERT_TZ('2011-08-08 06:00:00', 'UTC',@@global.time_zone))
有更好的方法吗?
In my database, I'm storing time as a BIGINT UTC value.
In my test data SQL dump I'd like to see the time in UTC for readability. However, the MySQL unix_timestamp function expects time in the local time zone, which I'm trying to avoid.
I've looked around and the only way I've found of converting the UTC time string to a unix time stamp is using this expression:
SELECT unix_timestamp(CONVERT_TZ('2011-08-08 06:00:00','UTC',@@global.time_zone))
Is there a better way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您将其存储为时间戳而不是 bigint,则只需设置时区就会自动发生。
另外,我实在不明白你在做什么。您将 unixtime 存储为 bigint 列是否正确?所以我不明白你为什么使用
unix_timestamp()
函数 - 转换为 unixtime,而不是从它转换。我想这就是你所需要的:
If you stored it as a timestamp instead of a bigint it would happen automatically just by setting the timezone.
Also, I don't really understand what you are doing. You are storing unixtime as your bigint column correct? So I don't get why you are using the
unix_timestamp()
function - that converts TO a unixtime, not from it.I guess this is what you need: