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

Get jQuery and JavaScript Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.