In MySQL caculating offset for a time zone

后端 未结 8 1776
死守一世寂寞
死守一世寂寞 2020-12-08 22:22

Is there a way in MySQL to calculate the offset for any timezone? For example, to get the local time in the timezone Asia/calcutta. What I want to do is calcula

8条回答
  •  攒了一身酷
    2020-12-08 22:55

    SELECT TIMESTAMPDIFF(HOUR, UTC_TIMESTAMP(), NOW());

    If the server's timezone is PST this will return -8.

    SELECT TIMESTAMPDIFF(SECOND, NOW(), UTC_TIMESTAMP());

    Add the result of the above to any unix timestamp if you want to compare it to MySQL DateTimes.

提交回复
热议问题