When a Date object is created, a number of methods allow you to operate on it.

Date methods allow you to get and set the year, month, day, hour, minute, second, and millisecond of date objects, using either local time or UTC (universal, or GMT) time.
 

Displaying Dates

JavaScript will (by default) output dates in full text string format:

Wed Mar 25 2015 05:30:00 GMT+0530 (India Standard Time)

When you display a date object in HTML, it is automatically converted to a string, with the toString() method.

Example

const d = new Date();
document.getElementById("demo").innerHTML = d;

Same as:

const d = new Date();
document.getElementById("demo").innerHTML = d.toString();
 

The toUTCString() method converts a date to a UTC string (a date display standard).

Example

const d = new Date();
document.getElementById("demo").innerHTML = d.toUTCString();
 

The toDateString() method converts a date to a more readable format:

Example

const d = new Date();
document.getElementById("demo").innerHTML = d.toDateString();
 

The toISOString() method converts a date to a string, using the ISO standard format:

Example

const d = new Date();
document.getElementById("demo").innerHTML = d.toISOString();



Practice Excercise Practice now