开发者

Find current time in ET: EST or EDT, as appropriate

I have an application whi开发者_StackOverflow社区ch 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.

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.


Tolerable method:

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜