In the below syntax, DateObj is a valid Date object created using Date() constructor whose contents of date portion are converted into string.
Parameters : This function does not takes any parameter. It is just used along with a Date object created using Date() constructor.
Return Values: It returns the converted string of Date() constructor content’s of date portion.
Below program illustrate the date.toDateString() function:-
Tue Oct 15 1996
Errors and Exceptions
Example 1: Here nothing as parameter is passed while creating date object but still toDateString() function return current day name, month name, date, year.
Mon Apr 23 2018
Example 2: When some random list of values is passed then toDateString() function return the corresponding produced string.
The format for Date() constructor is like Date(month, date, year, time). By following this format some values is given in the below program and corresponding string is produced as output. Time format should be like (number:number:number). If time do not lie in this format, it gives output as Invalid date.
Mon Jan 01 2001 Sat Feb 03 2001 Wed Apr 05 2006 Invalid Date Wed Apr 05 2006 Sun Dec 05 2004
Months, Date, hour, minute, second and millisecond should must be in their respective range of 0 to 11 for months, 1 to 31 for date, 0 to 23 for hours, 0 to 59 for minute, 0 to 59 second, 0 to 999 for milliseconds otherwise toDateString() function return Invalid Date.
Example 1 : Here date given as of 45 which is out of range of date that is why below code gives output as null.
- Google Chrome
- Internet Explorer
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.