Computer >> Computer tutorials >  >> Programming >> Javascript

How to convert a JavaScript date object to a string?


To convert a JavaScript date object to a string, use the toString() method. This method returns a string representing the specified Date object.

Example

You can try to run the following code to convert a date object to a string −

<html>
   <head>
      <title>JavaScript toString() Method</title>
   </head>
   <body>
      <script>
         var dateobject = new Date(2017, 9, 24, 14, 39, 7);
         stringobj = dateobject.toString();
         document.write( "String Object : " + stringobj );
      </script>
   </body>
</html>