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
精彩评论