Definition and Usage
toLocaleString() method can convert the Date object to String according to the local time, and return the result .
Syntax
dateObject.toLocaleString()
Return value
A string representation of the dateObject, expressed in the local time zone and formatted according to local rules.
Example
Example 1
In this example, we will convert today’s date into a string according to local time:
<script type="text/javascript"> var d = new Date() document.write(d.toLocaleString()) </script>
Output:
2017/11/8 下午2:06:15
Example 2
In this example, we will convert a specific date into a string according to local time:
<script type="text/javascript"> var born = new Date("July 21, 1983 01:15:00") document.write(born.toLocaleString()) </script>
Output:
1983/7/21 上午1:15:00
How Use toLocaleString() to convert today's date to a string based on local time.
<html> <body> <script type="text/javascript"> var d = new Date() document.write (d.toLocaleString()) </script> </body> </html>
Result:
2017/11/8 下午2:07:26
The above is the detailed content of JavaScript method toLocaleString() to convert a Date object into a string based on local time. For more information, please follow other related articles on the PHP Chinese website!