O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Getting Specific Date Components

var d = new Date("Sat Jan 04 2014 15:03:22 GMT-0700"); d.getDate(); //returns 4 d.getDay(); //returns 6 d.getFullYear(); //returns 2014 d.getHours(); //returns 15 d.getMinutes(); //returns 3 d.getMinutes(); //returns 22 d.getTime(); //returns 1388873002000 d.getTimeZoneOffset(); //returns 420

The Date object provides several methods to get the value of specific components of the date, such as year, day of month, day of week, and more. Table 2.5 lists the methods to get specific date components from the Date object.

Image

Table 2.5 Date Object Methods to Get Specific Date Components

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required