The Date object is a data type built into the JavaScript language. Date objects are created with the new Date( ) as shown below.
Once a Date object is created, a number of methods allow you to operate on it. Most methods simply allow you to get and set the year, month, day, hour, minute, second, and millisecond fields of the object, using either local time or UTC (universal, or GMT) time.
The valueOf() function of the date object returns its primitive value.
Syntax
Its Syntax is as follows
dateObj.valueOf()
Example
<html> <head> <title>JavaScript Example</title> </head> <body> <script type="text/javascript"> var dateObj = new Date('September 26, 89 12:4:25:96'); document.write("Current Time: "+dateObj.valueOf()); </script> </body> </html>
Output
Current Time: 622794865096
Example
If you do not pass anything to the constructor of the date object it returns the number of milliseconds from 1 January 1970 00:00:00 UTC to current date.
<html> <head> <title>JavaScript Example</title> </head> <body> <script type="text/javascript"> var dateObj = new Date('September 26, 89 12:4:25:96'); document.write("Current Time: "+dateObj.valueOf()); </script> </body> </html>
Output
Current Time: 622794865096
Example
Since we have maximum 31 days in a month the date should be between 1 to 31 else this function returns NaN.
<html> <head> <title>JavaScript Example</title> </head> <body> <script type="text/javascript"> var dateObj = new Date('September 38, 1989'); document.write("Current Time: "+dateObj.valueOf()); </script> </body> </html>
Output
Current Time: NaN