DailyJS

ECMAScript 5's Date Extensions

Alex R. Young

Subscribe

@dailyjs

Facebook

Google+

ecmascript date

ECMAScript 5's Date Extensions

Posted by Alex R. Young on .
Featured

ecmascript date

ECMAScript 5's Date Extensions

Posted by Alex R. Young on .

One of the changes that ECMAScript 5 introduces is extensions to the
Date class. Some of these are very useful --
Date.now and Date.UTC as well as ISO-8601
format support.

Michael J. Ryan has written support for these API changes in
DateExtensions.js so you can get started using them now.

Usage looks like this:

var epoch1 = new Date("1970-01-01T00:00:00.000Z");
var epoch2 = new Date(0);

if (epoch1.getTime() == epoch2.getTime())
    alert("Epochs match!");

alert(epoch1.toString()); //localized date instance of the JS epoch
alert(epoch2.toISOString()); // "1970-01-01T00:00:00.000Z"
alert(epoch1 instanceof Date); // true
alert(Date.UTC(1970,0,1,0,0,0,0)); // 0

More on ECMAScript

Other ECMAScript 5 extensions to the base library include:

You can read a PDF of the spec here:
ECMA-262.pdf