The JavaScript toDateString function returns the Date portion of a given date in a human-readable format. The syntax of the JavaScript toDateString Date function is:
Date.toDateString()
JavaScript toDateString Function Example
We use the toDateString function to return the data portion of today’s date.
<!DOCTYPE html> <html> <head> <title> JavaScript toDateString Function </title> </head> <body> <h1> JavaScript toDateString Example </h1> <script> var dt = Date(); document.write("Date and Time : " + dt + "<br/>"); var x = dt.toDateString(); document.write("After toDateString() = " + x); </script> </body> </html>
OUTPUT
JavaScript to Date String Function Example 2
This JavaScript toDateString example returns the string date of a custom date in a human-readable format.
<!DOCTYPE html> <html> <head> <title> JavaScript toDateString Function </title> </head> <body> <h1> JavaScript toDateString Example </h1> <script> var dt = Date(2017, 5, 15, 10, 11, 19); document.write("Date and Time : " + dt + "<br/>"); var x = dt.toDateString(); document.write("After toDateString() = " + x); </script> </body> </html>
OUTPUT