avascript日期toLocaleString是否为DST帐

avascript日期toLocaleString是否为DST帐

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

问题描述

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



  var deadline = new Date('5/1/2013'+16:15+'UTC'); 
alert(deadline.toLocaleString());


解决方案

我们不知道什么是 toLocaleString 方法( ):

但是,大多数实现将考虑DST,如果它是活动的在当前的当地时区。为了你的例子,我得到Mittwoch,1. Mai 2013 18:15:00 - 。

我想你可以信任 toLocaleString - 浏览器应该尊重用户的设置。如果您想手动执行,请查看。


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):

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.

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帐号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 10:36