JavaScript | date.toTimeString() function
The date.toTimeString() is an inbuilt function in JavaScript which is used to return the time portion of the given date object in english.The date object is created using date() constructor.
Syntax:
dateObj.toTimeString()
Note: In the above syntax, DateObj is a valid Date object created using Date() constructor whose time portion contents is returned.
Parameters: This function does not takes any parameter. It is just used along with a Date object created using Date() constructor whose time portion contents is returned in English like language.
Return Values: It return the time portion of the given date object in english.
Below program illustrate the date.toTimeString() function:-
<script> // Here a date has been assigned // while creating Date object var dateobj = new Date('October 15, 1996 05:35:32'); // Contents of above date object // of time portion is returned // using toTimeString() function. var B = dateobj.toTimeString(); // Printing the time. document.write(B); </script> |
Output:
05:35:32 GMT+0530 (India Standard Time)
- Here nothing as parameter is passed while creating date object but still toTimeString() function return current time.
<script>// Here nothing has been assigned// while creating Date objectvardateobj =newDate();// It return current time using// toTimeString() function.varB = dateobj.toTimeString();// Printing the current time.document.write(B);</script>chevron_rightfilter_noneOutput:
14:58:08 GMT+0530 (India Standard Time)
- When time part is not given to the parameter of Date() constructor then it return the time as zeros(0).
<script>// Only month date and year are// assigned without time while// creating Date object.vardateobj =newDate('October 15, 1996');// It returns time using// toTimeString() function.varB = dateobj.toTimeString();// Printing the time.document.write(B);</script>chevron_rightfilter_noneOutput:
00:00:00 GMT+0530 (India Standard Time)
Exceptional cases associated with this function:
Supported Browsers: The browsers supported by JavaScript date.toTimeString() Function are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari
Recommended Posts:
- How to call a function that return another function in JavaScript ?
- JavaScript | Array every() function
- JavaScript | toExponential() Function
- Javascript | Number() Function
- JavaScript | Math.abs( ) function
- JavaScript | Array some() function
- JavaScript | Math.E() function
- JavaScript | String() Function
- JavaScript | toPrecision( ) Function
- JavaScript | Function binding
- JavaScript | toString( ) function
- JavaScript | Symbol.for() function
- JavaScript | toFixed( ) Function
- JavaScript | Array.of() function
- JavaScript | Function Call
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



