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

How to convert a date object to string with format hh:mm:ss in JavaScript?


To convert a date object to string with format hh:mm: ss, use the toISOString() method. It converts using ISO standard i.e. −

YYYY-MM-DDTHH:mm:ss.sssZ

Example

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

<html>
   <head>
      <title>JavaScript Dates</title>
   </head>
   <body>
      <script>
         var date, res;

         date = new Date();
         res = date.toISOString();

         document.write(res);
      </script>
   </body>
</html>

Output

2018-05-25T09:55:53.518