What timezone does MySQL's NOW() follow

前端 未结 3 829
你的背包
你的背包 2020-12-10 12:34

Does MySQL\'s NOW() follow the system\'s timezone or some standard like GMT or UTC?

相关标签:
3条回答
  • 2020-12-10 13:12

    As far as I know its the system clock is returned. Check for your system's time zone. I you connect MySQL locally (like from PHP) time zones will not matter for MySQL, I prefer handling them in PHP.

    0 讨论(0)
  • 2020-12-10 13:16

    It's in the current time zone. From the 5.1 docs:

    Returns the current date and time as a value in 'YYYY-MM-DD HH:MM:SS' or YYYYMMDDHHMMSS.uuuuuu format, depending on whether the function is used in a string or numeric context. The value is expressed in the current time zone.

    Now "the current time zone" can mean different things:

    • The system time zone
    • A time zone specified for the MySQL server in general
    • A connection-specific time zone

    More details are in the 5.1 time zone documentation.

    (The 5.4 docs look the same for these bits. Obviously consult the docs for the version you're running for the best possible information.)

    0 讨论(0)
  • 2020-12-10 13:18

    Per the docs, the rules are complicated, but mostly boil down to "current session's timezone" (which defaults to system timezone):

    The current session time zone setting affects display and storage of time values that are zone-sensitive. This includes the values displayed by functions such as NOW() or CURTIME(), and values stored in and retrieved from TIMESTAMP columns. Values for TIMESTAMP columns are converted from the current time zone to UTC for storage, and from UTC to the current time zone for retrieval.

    Of course you can use UTC_TIMESTAMP() if you need UTC specifically.

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