Home  >  Article  >  Web Front-end  >  How to convert a date to a string using the current locale's conventions?

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

PHPz
PHPzforward
2023-08-28 10:41:06885browse

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>

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!

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