.toDateString()

Published Dec 22, 2023
Contribute to Docs

When applied to a Date object, .toDateString() retrieves the date portion of the object’s value, and returns a string representation of this date in a locale-specific format.

Syntax

dateObject.toDateString()

Example

In this example, a new instance of the Date object is created and stored in the variable, date. The .toDateString() method is then called on date, and the string returned is stored in dateString and printed out on the console:

const date = new Date('December 5, 2023 8:53');
let dateString = date.toDateString();
console.log(dateString);

The above example will give the following output:

Tue Dec 05 2023

Codebyte Example

Run the code displayed below to see how the .toDateString() method works. Feel free to play around with the inputs and see what happens to the output.

us
Visit us
code
Hide code
Code
Output
Hide output
Hide output
Loading...

All contributors

Looking to contribute?

Learn JavaScript on Codecademy