&n"/> JavaScripttoTimeStringMethod &n">

Home >Web Front-end >HTML Tutorial >How to return the 'time' part of a date as a readable string

How to return the 'time' part of a date as a readable string

王林
王林forward
2023-09-14 20:49:021327browse

How to return the time part of a date as a 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 the Date object in human-readable form.

Example

You need to run the following code to return only the time portion of the 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>

The above is the detailed content of How to return the 'time' part of a date as a readable string. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete