MySql - SELECT TimeStamp Column in UTC format

前端 未结 3 990
既然无缘
既然无缘 2020-12-31 05:07

In my Mysql 5.0 DB I have a column to control LastUpdated information. The Column is a TimeStamp one and MySql automatic updates data.

I\'m trying to select this co

相关标签:
3条回答
  • 2020-12-31 05:33

    Besides changing the default timezone of the server, the timezone can also be adjusted per connection by executing this SQL statement:

    SET time_zone = timezone;
    

    Where timezone is the name of the timezone (see MySQL docs).

    Alternatively, you can also convert a timestamp to a different timezone using the CONVERT_TZ function.

    0 讨论(0)
  • 2020-12-31 05:37

    I needed to alter this to add the "Z" at the end of other things (i.e. like jQuery timeago) knew the time was UTC:

    SELECT 
    CONCAT(CONVERT_TZ(`timestamp_field`, @@session.time_zone, '+00:00'), 'Z') 
         AS `utc_datetime` 
    FROM `table_name`
    
    0 讨论(0)
  • 2020-12-31 05:38
    SELECT 
    CONVERT_TZ(`timestamp_field`, @@session.time_zone, '+00:00') AS `utc_datetime` 
    FROM `table_name`
    

    I made a cheatsheet here: Should MySQL have its timezone set to UTC?

    0 讨论(0)
提交回复
热议问题