To return a string representing the source for an equivalent Date object, use the JavaScript toSource() method. This method returns a string representing the source code of the object.
Example
You can try to run the following code to return a string representing the source for an equivalent Date object −
<html> <head> <title>JavaScript toSource() Method</title> </head> <body> <script> var dt = new Date(2018, 0, 15, 14, 39, 7); document.write( "Formated Date : " + dt.toSource() ); </script> </body> </html>