Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do `getUTCSeconds` and `getUTCMilliseconds` functions exist?

Tags:

javascript

Wouldn't these values always been the same as getSeconds and getMilliseconds?

like image 400
Matt Avatar asked Mar 07 '13 05:03

Matt


1 Answers

The adustment between local time and UTC time is based on an offset specified as a number of milliseconds.

http://es5.github.com/#x15.9.1.7 says

15.9.1.7 Local Time Zone Adjustment

An implementation of ECMAScript is expected to determine the local time zone adjustment. The local time zone adjustment is a value LocalTZA measured in milliseconds which when added to UTC represents the local standard time. Daylight saving time is not reflected by LocalTZA. The value LocalTZA does not vary with time but depends only on the geographic location.

As to when this is useful, http://bugs.python.org/issue5288 explains an API problem that arose from assuming that timezone offsets were an integral number of minutes:

The Olson time zone database (used by most UNIX systems and Mac OS X) has a number of time zones with historic offsets that use second resolution (from before those locations switched to a rounded offset from GMT).

Once you get down to second resolution, not having a getUTCMillis just seems an odd asymmetry.

like image 101
Mike Samuel Avatar answered Nov 14 '22 21:11

Mike Samuel