.toDateString()
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.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.