使用 mysql 将纪元时间转换为 gmt

Convert epoch time to gmt using mysql

我 运行 无法将时间转换为 utc/gmt。

 select from_unixtime(1623167869);
 2021-06-08 11:57:49

GMT 应该 return 2021-06-08 14:57:49.

FROM_UNIXTIME

return 值以 会话时区 表示。

https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_from-unixtime

> SET time_zone = '+00:00';SELECT @@SESSION.time_zone;select from_unixtime(1623167869);
Query OK, 0 rows affected (0.000 sec)

+---------------------+
| @@SESSION.time_zone |
+---------------------+
| +00:00              |
+---------------------+
1 row in set (0.000 sec)

+---------------------------+
| from_unixtime(1623167869) |
+---------------------------+
| 2021-06-08 15:57:49       |
+---------------------------+
1 row in set (0.000 sec)

> SET time_zone = '-02:00';SELECT @@SESSION.time_zone;select from_unixtime(1623167869);
Query OK, 0 rows affected (0.000 sec)

+---------------------+
| @@SESSION.time_zone |
+---------------------+
| -02:00              |
+---------------------+
1 row in set (0.000 sec)

+---------------------------+
| from_unixtime(1623167869) |
+---------------------------+
| 2021-06-08 13:57:49       |
+---------------------------+
1 row in set (0.000 sec)