Javascript日期toLocaleString是否为DST帐号? [英] Does Javascript date toLocaleString account for DST?
问题描述
http://javascript.about.com/library/bldst.htm
var deadline = new Date('5/1/2013'+16:15+'UTC');
alert(deadline.toLocaleString());
我们不知道什么是 toLocaleString
方法(§15.9.5.5 ):
此函数返回一个String值。字符串的内容是
实现依赖,但是旨在以方便,可读的形式表示当前时区的
中的日期
对应于主机环境当前的
语言环境的约定。
但是,大多数实现将考虑DST,如果它是活动的在当前的当地时区。为了你的例子,我得到Mittwoch,1. Mai 2013 18:15:00
- CEST 。
我需要插入附加代码来检查用户的位置,然后修复显示的时间?
我想你可以信任 toLocaleString
- 浏览器应该尊重用户的设置。如果您想手动执行,请查看 timezone.js 。
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 for daylight savings if they are in a timezone that recognizes it? Or will I need to insert additional code that checks where the user is, and then fixes the displayed time?
http://javascript.about.com/library/bldst.htm
var deadline = new Date('5/1/2013 ' + "16:15" + ' UTC');
alert(deadline.toLocaleString());
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.
这篇关于Javascript日期toLocaleString是否为DST帐号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!