Javascript日期toLocaleString是否为DST帐号? [英] Does Javascript date toLocaleString account for DST?

查看:107
本文介绍了Javascript日期toLocaleString是否为DST帐号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了UTC的最后期限,如下所示,我想知道toLocaleString()方法到底在用户的本地机器上会做什么。例如,如果它们在识别它的时区,它会占用夏令时吗?或者我需要插入附加的代码来检查用户的位置,然后修改显示的时间?



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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆