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

How to return the time portion of the Date as a human-readable string.


To return the “time” portion of the Date as a human-readable string, use the toTimeString() method in JavaScript. This method returns the time portion of a Date object in the human-readable form.

Example

You need to run the following code to return only the time portion of a Date −

<html>
   <head>
      <title>JavaScript toTimeString Method</title>
   </head>

   <body>
      <script>
         var dateobject = new Date(2018, 0, 1, 14, 39, 7);
         document.write( dateobject.toTimeString() );
      </script>
   </body>
</html>