.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.
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.
Learn JavaScript on Codecademy
- Career path
Front-End Engineer
Front-end engineers work closely with designers to make websites beautiful, functional, and fast.Includes 34 CoursesWith Professional CertificationBeginner Friendly115 hours - Free course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner Friendly15 hours