JavaScript Date Time Object Tutorial

JavaScript Date Object

The Date object is used to work with dates and times. Date objects are created with new Date().

There are four ways of instantiating a date:

var d = new Date();
var d = new Date(milliseconds);
var d = new Date(dateString);
var d = new Date(yearmonthdayhoursminutessecondsmilliseconds);

Date Object Properties

Sr.NoProperty & Description
1constructor Specifies the function that creates an object’s prototype.
2prototype The prototype property allows you to add properties and methods to an object

Date Methods

Here is a list of the methods used with Date and their description.

Sr.NoMethod & Description
1Date() Returns today’s date and time
2getDate() Returns the day of the month for the specified date according to local time.
3getDay() Returns the day of the week for the specified date according to local time.
4getFullYear() Returns the year of the specified date according to local time.
5getMinutes() Returns the minutes on the specified date according to local time.
6getMilliseconds() Returns the milliseconds in the specified date according to local time.
7getMonth() Returns the month on the specified date according to local time.
8getMonth() Returns the month in the specified date according to local time.
9getSeconds() Returns the seconds in the specified date according to local time.
10getTime() Returns the numeric value of the specified date as the number of milliseconds since January 1, 1970, 00:00:00 UTC.
11getTimezoneOffset() Returns the time-zone offset in minutes for the current locale.
12getUTCDay() Returns the day of the week on the specified date according to universal time.
13getUTCFullYear() Returns the year on the specified date according to universal time.
14getUTCHours() Returns the hours on the specified date according to universal time.
15getHours() Returns the hour on the specified date according to local time.
16getUTCMilliseconds() Returns the milliseconds in the specified date according to universal time.
17getUTCDate() Returns the day (date) of the month on the specified date according to universal time.
18getUTCMinutes() Returns the minutes on the specified date according to universal time.
19getUTCSeconds() Returns the seconds in the specified date according to universal time.
20getUTCMonth() Returns the month on the specified date according to universal time.
21setDate() Sets the day of the month for a specified date according to local time.
22setFullYear() Sets the full year for a specified date according to local time.
23setHours() Sets the hours for a specified date according to local time.
24setMilliseconds() Sets the milliseconds for a specified date according to local time.
25setMinutes() Sets the minutes for a specified date according to local time.
26setMonth() Sets the month for a specified date according to local time.
27setSeconds() Sets the seconds for a specified date according to local time.
28setTime() Sets the Date object to the time represented by a number of milliseconds since January 1, 1970, 00:00:00 UTC.
29setUTCDate() Sets the day of the month for a specified date according to universal time.
30setUTCFullYear() Sets the full year for a specified date according to universal time.
31setUTCHours() Sets the hour for a specified date according to universal time.
32setUTCMilliseconds() Sets the milliseconds for a specified date according to universal time.
33setUTCMinutes() Sets the minutes for a specified date according to universal time.
34setUTCMonth() Sets the month for a specified date according to universal time.
35setUTCSeconds() Sets the seconds for a specified date according to universal time.
36setYear() Deprecated – Sets the year for a specified date according to local time. Use setFullYear instead.
37toDateString() Returns the “date” portion of the Date as a human-readable string.
38toGMTString() Deprecated – Converts a date to a string, using the Internet GMT conventions. Use toUTCString instead.
39toLocaleDateString() Returns the “date” portion of the Date as a string, using the current locale’s conventions.
40toLocaleFormat() Converts a date to a string, using a format string.
41toLocaleString() Converts a date to a string, using the current locale’s conventions.
42toLocaleTimeString() Returns the “time” portion of the Date as a string, using the current locale’s conventions.
43toSource() Returns a string representing the source for an equivalent Date object; you can use this value to create a new object.
44toString() Returns a string representing the specified Date object.
45toTimeString() Returns the “time” portion of the Date as a human-readable string.
46toUTCString() Converts a date to a string, using the universal time convention.
47valueOf() Returns the primitive value of a Date object.

Example: JavaScript getDate() Method

Example: JavaScript getMilliseconds() Method

Take Your Free Live Demo Class Now

We Will Call Back You Shortly

Enter Your DETAILS BELOW

We Will Send You the Course Fees Details In Below Number

Enter Your DETAILS BELOW

We Will Call Back You Shortly

Enter Your DETAILS BELOW

We Will Call Back You Shortly

Enter Your DETAILS BELOW

Enter Your DETAILS BELOW TO take

free demo class