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

JavascriptWeb DevelopmentFront End Technology

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 −

Live Demo

<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
raja
Published on 14-Feb-2018 12:35:51
Advertisements