JavaScript Date Reference

The JavaScript Date object is important for handling dates and times in web development. It provides various methods to create, manipulate, and format dates. Understanding the Date object and its methods allows you to work effectively with dates and times in your applications. This guide covers the key features and methods of the JavaScript Date object, helping you to manage date and time data efficiently.

Syntax:

new Date();

Example: If nothing as the parameter is given, it returns the present date and time.

Javascript
// If nothing as a parameter is given,
// it represents the present date and time.
let A = new Date();

// Printing present date and time.
console.log(A);

Output:

Mon Nov 14 2022 16:56:38 GMT+0530 (India Standard Time)

The complete list of JavaScript Date methods and properties are listed below:

JavaScript Date Constructor: A constructor gets called when an object is created using the new keyword.

ConstructorDescriptionExamples
Date()Create a Date instance or return a string representing the current time.
Try

JavaScript Date Properties: A JavaScript property is a member of an object that associates a key with a value.

  • Instance Properties: An instance property is a property that has a new copy for every new instance of the class.
PropertiesDescriptionExamples
constructorReturns the constructor function for an object.
Try

JavaScript Date Methods: JavaScript methods are actions that can be performed on objects.

  • Static Method: If the method is called using the Date class itself then it is called a static method.
Static MethodsDescriptionExamples
now()Return the number of milliseconds elapsed since January 1, 1970, 00:00:00 UTC.
Try
parse()Return the time difference in milliseconds from, January 1, 1970, till the date we provide.
Try
UTC()Return the number of milliseconds in a Date object since January 1, 1970, 00:00:00, universal time.
Try
  • Instance Method: If the method is called on an instance of a date object then it is called an instance method.
Instance MethodsDescriptionExamples
getDate()Fetch the date of a month from a given Date object.
Try
getDay()Fetch the day of a week(0 to 6) from a given Date object.
Try
getFullYear()Fetch the year from a given Date object.
Try
getHours()Return the hours from a given Date object.
Try
getMilliseconds()Fetch the milliseconds from a given Date object.
Try
getMinutes()Fetch the minutes from the given Date object.
Try
getMonth()Fetch the month(0 to 11) from the given Date object.
Try
getSeconds()Fetch the seconds from the given Date object.
Try
getTime()Return the number of milliseconds since 1 January 1970 .
Try
getTimezoneOffset()Return the time difference between in minutes.
Try
getUTCDate()Fetch the date of a month according to universal time from a given Date object.
Try
getUTCDay()Fetch the date of a month according to universal time from a given Date object.
Try
getUTCFullYear()Fetch the year according to universal time from a given Date object.
Try
getUTCHours()Fetch the hours according to universal time from a given Date object.
Try
getUTCMilliseconds()Fetch the millisecond according to universal time from a given Date object.
Try
getUTCMinutes()Fetch the minutes according to universal time from a given Date object.
Try
getUTCMonth()Fetch the month according to universal time from a given Date object.
Try
getUTCSeconds()Fetch the second according to universal time from a given Date object
Try
getYear()Get the year on a specified date according to universal time.
Try
setDate()Set the date of a month into a date object which is created using date() constructor.
Try
setFullYear()Set year into a date object which is created using Date() constructor.
Try
setHours()Set hours into a date object which is created using the Date() constructor.
Try
setMilliseconds()Set milliseconds into a date object which are created using date() constructor.
Try
setMinutes()Set minutes into a Date object which is created using Date() constructor.
Try
setMonth()Set month into a date object which is created using the Date() constructor.
Try
setSeconds()Set seconds into a Date object which is created using Date() constructor.
Try
setUTCDate()Set date of a month according to universal time into a date object.
Try
setUTCFullYear()Set year into a date object according to universal time.
Try
setUTCHours()Set hours into a date object according to universal time.
Try
setUTCMilliseconds()Set milliseconds according to universal time into a date object.
Try
setUTCMinutes()Set minutes according to universal time into a date object.
Try
setUTCMonth()Set month according to universal time into a date object.
Try
setUTCSeconds()Set seconds according to universal time into a date object.
Try
setYear()Set the year in a specified date according to universal time.
Try
toDateString()Convert the given date object’s contents of the date portion into a string.
Try
toISOString()Convert the given date object’s contents into a string in ISO format (ISO 8601).
Try
toJSON()Convert the given date object’s contents into a string.
Try
toLocaleDateString()Convert a date to a string.
Try
toLocaleTimeString()Fetch the time from a given Date object.
Try
toLocaleString()Convert a date and time to a string.
Try
toString()Convert the given date object’s contents into a string.
Try
toTimeString()Return the time portion of the given date object in English.
Try
toUTCString()Convert the given date object’s contents into a string according to the universal time zone UTC.
Try
valueOf()Get the number of milliseconds between 1 January 1970 00:00:00 UTC and the given date.
Try