将Unix时间转换为UTC日期时间 [英] Convert unix time to UTC datetime
问题描述
我正在尝试将时间戳记插入数据库,我需要将时间戳记为UTC时间,而不是服务器的时区。
I'm trying to insert a timestamp into the database, I need the timestamp to be in UTC time, not the server's time zone.
INSERT INTO my_table SET time = FROM_UNIXTIME(:epochTime)
但是新插入的日期时间值不是UTC时间,该怎么办?
But the newly inserted datetime value is not in UTC time, how can I do this?
也许我也应该使用 CONVERT_TZ ,但是我不知道转换时区。
Perhaps I should also use CONVERT_TZ, but I don't know the timezone from which I convert.
推荐答案
是的,我来看一下CONVERT_TZ:
Yup I would look at CONVERT_TZ:
> http://dev.mysql.com/doc/refman/ 5.1 / en / date-and-time-functions.html#function_convert-tz
要从mysql获取时区:
To grab the timezone from mysql:
mysql> SELECT @@global.time_zone, @@session.time_zone;
编辑:下面的查询返回当前会话的时区。
The query below returns the timezone of the current session.
select timediff(now(),convert_tz(now(),@@session.time_zone,'+00:00'));
某些信息的网址:如何获取MySQL的当前时区?
如果服务器的时区不同,请告诉我们您的操作系统或位置。
If the server has a different timezone, tell us your Operating system or location.
这篇关于将Unix时间转换为UTC日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!