Does Javascript date toLocaleString account for DST?

后端 未结 3 821
礼貌的吻别
礼貌的吻别 2021-01-24 00:46

I have set a deadline in UTC, as shown below, and I\'m wondering what exactly the toLocaleString() method will do to it on user\'s local machines. For instance, will it account

3条回答
  •  梦毁少年i
    2021-01-24 01:07

    We don't know what exactly the toLocaleString method does (§15.9.5.5):

    This function returns a String value. The contents of the String are implementation-dependent, but are intended to represent the Date in the current time zone in a convenient, human-readable form that corresponds to the conventions of the host environment’s current locale.

    But yes, most implementations will consider DST if it is active in the current local timezone. For your example I'm getting "Mittwoch, 1. Mai 2013 18:15:00" - CEST.

    Will I need to insert additional code that checks where the user is, and then fixes the displayed time?

    I think you can trust toLocaleString - the browser should respect the user's settings. If you want to do it manually, check out timezone.js.

提交回复
热议问题