Time zones and Localisation

后端 未结 5 1330
轻奢々
轻奢々 2021-01-16 06:27

I\'m currently storing all times in UTC, to make things easier for when I start bringing multiple sites and servers online.

The problem comes in when translating

5条回答
  •  礼貌的吻别
    2021-01-16 07:05

    You can, using javascript (which knows the local time), change the user-inputted time to UTC before sending the data to your server. Then, send UTC down in a format such that javascript can turn it from UTC into local time.

    For example, a date to UTC to be sent to the server:

    (new Date("November 11, 2011 23:13:42")).toUTCString()
    

    And UTC to local time, for rendering:

    (new Date("October 17, 1986 15:29:13 UTC")).toLocaleString()
    

提交回复
热议问题