Home > Article > Web Front-end > JavaScript method toLocaleString() to convert a Date object into a string based on local time
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:
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:
Output:
1983/7/21 上午1:15:00
How Use toLocaleString() to convert today's date to a string based on local time.
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!