
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).
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>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!