The first thing that we need to do to be able to manipulate dates and/or times is to create a Date object.
1 var today = new Date();
2 var thatDay = new Date(year, month, day, hour, minute, second, milliseconds);
3 var janone1970 = new Date(0);
4 var myDate = new Date(textdate);
retrieve or set the day of the month
retrieve or set the month of the year (numbered one less than the usual month numbering since the value is expected to be used to reference an array of month names so as to retrieve that name).
retrieve or set the four digit year
retrieve or set the hour of the day (numbered between 0 and 23)
retrieve or set the minute within the hour (numbered between 0 and 59)
retrieve or set the second within the minute (also numbered 0 to 59)
Note that there is a second set of methods identical to those listed above apart from having UTC between the get/set and the unit name (eg. today.getUTCDate()). These methods work exactly the same as the above methods except that while the above methods work based on the current timezone used on the computer where the browser is running, the UTC versions apply the timezone offset in order to determine the equivalent Universal Coordinated Time (also known as GMT or z time).
There are also a number of additional methods that can be used to retrieve date/time information in other formats.
retrieve the day of the week for the local timezone and UTC respectively.
retrieve the number of milliseconds since midnight on 1st January 1970 for the local timezone and UTC respectively.
retrieve the number of minutes difference between local and UTC time. Note that since this is a fixed value we don't need to reference any specific date object to get it but can instead reference the base Date object itself (this is known as a static method call).
another static method call, this one converts any text string that can be interpreted as a date into the corresponding number of milliseconds since 1st January 1970
extract the date and time in a locale specific format
extract the date in a locale specific format
extract the time in a locale specific format
extract the date and time in a browser specific format
extract the date in a browser specific format
extract the time in a browser specific format
extract the UTC date and time in a browser specific format and label it as either GMT or UTC
extract the number of milliseconds since 1st January 1970
This article written by Stephen Chapman, Felgall Pty Ltd.