How can I use the current locale's convention of returning the 'time' part of a date as a string?

PHPz
Release: 2023-08-25 21:57:12
forward
1302 people have browsed it

How can I use the current locales convention of returning the time part of a date as a string?

To return the "time" portion of the date as a string using the conventions of the current locale, use the toLocaleTimeString() method.

The toLocaleTimeString method relies on the underlying operating system for formatting dates. It converts the date to a string using the format conventions of the operating system the script is running on. For example, in the United States, the month appears before the date (04/15/98), while in Germany, the day appears before the month (15.04.98).

Example

You can try running the following code to return the "time" part of the date as a string -

<html>
   <head>
      <title>JavaScript toLocaleTimeString Method</title>
   </head>
   <body>
      <script>
         var dt = new Date(2018, 0, 15, 14, 16, 30);
         document.write( "Formated Date - Time : " + dt.toLocaleTimeString() );
      </script>
   </body>
</html>
Copy after login

The above is the detailed content of How can I use the current locale's convention of returning the 'time' part of a date as a string?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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