How to convert a date to a string using the current locale's conventions?

PHPz
Release: 2023-08-28 10:41:06
forward
883 people have browsed it

How to convert a date to a string using the current locales conventions?

JavaScript Date toLocaleString() The method converts a date to a string using the operating system's native convention.

The toLocaleString 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 understand how to convert a date to a string using the conventions of the current locale -
<html>
   <head>
      <title>JavaScript toLocaleString Method</title>
   </head>

   <body>
      <script>
         var dt = new Date(2018, 0, 15, 14, 39, 7);
         document.write( "Formated Date : " + dt.toLocaleString() );
      </script>
   </body>
</html>
Copy after login

The above is the detailed content of How to convert a date to a string using the current locale's conventions?. 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