![]() |
VOOZH | about |
The date.toLocaleTimeString() method is used to fetch the time from a given Date object.
Syntax:
DateObj.toLocaleTimeString()
Parameter: This method does not accept any parameter. It is just used along with a Date Object from which we want to fetch the time.
Return Values: It returns a string which is the time from the given Date object.
Note: The DateObj is a valid Date object created using the Date() constructor from which we want to fetch the time.
Below are examples of the Date toLocaleTimeString() method.
Example:
Output:
5:35:32
Example 2: The date of the month should lie between 1 to 31 because none of the months have a date greater than 31 that is why it returns an Invalid Date because the date for the month does not exist. Hence, the Year will not have existed when the date of the month is given as 36 i.e., greater than 31.
Output:
Invalid Date
Example 3: If nothing as a parameter is given to the Date() constructor the current date is passed in the Date object and hence toLocaleTimeString() will return the current time.
Output:
4:09:16
We have a complete list of Javascript Date Objects, to check those please go through this article.
Supported Browsers: The browsers supported by JavaScript Date toLocaleTimeString() method are listed below:
We have a Cheat Sheet on JavaScript where we covered all the important topics of JavaScript to check those please go through