The JavaScript Date Object

The JavaScript library has an object called Date. Unlike for example the Math object, the Date object methods cannot be accessed in the Date object raw state, we must instantiate a sample of the Date object to work with, almost like getting a license to use its methods on our script.

If we call Date by itself…


JavaScript returns today’s complete date, like for example “Sat Jun 21 2014 16:02:33 GMT-0400 (Eastern Daylight Time)“.

Creating a working Date object instance.

We create an instance of Date with the new keyword, like for example:

var sampleDate = new Date;

Access your Chrome or Opera JS Console by pressing CTRL SHIFT j and try it yourself.

Once we have an instance of the object Date we can use it as an interface in order to access Date methods from the JavaScript library:

// returns today's monthly day. Example: 21
// returns 2014

The idea of a blog is to be brief and to the point. However, in my JavaScript Objects Functions and Arrays Explained eBook I write in extensive detail about these methods and how to use them in real life.

See you there!