
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Date.toTimeString() function in JavaScript
The Date object is a data type built into the JavaScript language. Date objects are created with the new Date( ) as shown below.
Once a Date object is created, a number of methods allow you to operate on it. Most methods simply allow you to get and set the year, month, day, hour, minute, second, and millisecond fields of the object, using either local time or UTC (universal, or GMT) time.
The toTimeString() function of the date object returns the time in the date object.
Syntax
Its Syntax is as follows
dateObj.toTimeString()
Example
<html> <head> <title>JavaScript Example</title> </head> <body> <script type="text/javascript"> var dateObj = new Date('September 26, 89 12:4:25:96'); document.write("Current Time: "+dateObj.toTimeString()); </script> </body> </html>
Output
Current Time: 12:04:25 GMT+0530 (India Standard Time)
Example
If you do not pass a parameter to the constructor while creating a date object this function returns the current time.
<html> <head> <title>JavaScript Example</title> </head> <body> <script type="text/javascript"> var dateObj = new Date(); document.write("Current Time: "+dateObj.toTimeString()); </script> </body> </html>
Output
Current Time: 14:56:58 GMT+0530 (India Standard Time)
Example
If you do not mention time in the constructor while creating a date object this function returns the time as 0.
<html> <head> <title>JavaScript Example</title> </head> <body> <script type="text/javascript"> var dateObj = new Date('September 26, 89'); document.write("Current Time: "+dateObj.toTimeString()); </script> </body> </html>
Output
Current Time: 00:00:00 GMT+0530 (India Standard Time)
- Related Articles
- Function returning another function in JavaScript
- Function Expression vs Function Declaration in JavaScript?
- ArrayBuffer.isView() function in JavaScript
- ArrayBuffer.slice() function in JavaScript
- Atomics.add() function in JavaScript
- Atomics.and() function in JavaScript
- Atomics.or() function in JavaScript
- Atomics.isLockFree() function in JavaScript
- Atomics.load() function in JavaScript
- Atomics.store() function in JavaScript
- Atomics.sub() function in JavaScript
- Atomics.xor() function in JavaScript
- DataView.getFloat32() function in JavaScript
- DataView.getFloat64() function in JavaScript
- DataView.getInt16() function in JavaScript

Advertisements