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

王林
Release: 2023-09-14 20:49:02
forward
1326 people have browsed it

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>
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template