在ET中找到当前时间:EST或EDT,视情况而定 [英] Find current time in ET: EST or EDT, as appropriate
问题描述
我有一个应用程序需要使用东部时间进行计算的某个部分而不是当地时间。我想这一切都可以手动完成(提取UTC时间,通过表查找确定夏令时是否有效,然后根据需要调整4或5小时)但我想知道是否有内置的方法来执行此操作。
I have an application which needs to use Eastern Time for a certain part of the calculation rather than the local time. I suppose this could all be done manually (extract UTC time, decide whether daylight savings is in effect by a table lookup, then shift by 4 or 5 hours as appropriate) but I wondered if there was a built-in way of doing this.
另外,最近美国的DST没有变化吗? (我需要遵循美国关于夏令时的规则。)我想知道这些是否已经纳入JavaScript版本,如果它遵循旧规则,或者它是否从一开始就不知道它们。
Also, weren't there changes to DST recently in the US? (I need to follow US rules on daylight savings.) I wonder if those were incorporated into JavaScript releases, if it follows the old rules, or if it never knew about them in the first place.
推荐答案
可容忍的方法:
var d, lsm, lso, off;
d = lsm = lso = new Date;
var off = d.getTimezoneOffset();
lsm.setMonth(2);
lsm.setDate(11);
lsm.setDate(11-lsm.getDay());
lso.setMonth(10);
lso.setDate(4);
lso.setDate(4-lso.getDay());
d.setMinutes(d.getMinutes()+off-(d < lsm || d >= lso ? 300 : 240));
// d contains the ET date
这篇关于在ET中找到当前时间:EST或EDT,视情况而定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!