Return String Representing Source for Equivalent Date Object



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>
Updated on: 2020-06-23T08:07:54+05:30

87 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements