C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript Date toTimeString() methodThe JavaScript date toTimeString() method returns the time portion of a Date object in the form of string. SyntaxThe toTimeString() method is represented by the following syntax: dateObj.toTimeString() ReturnA string representing the time portion of a Date object. JavaScript Date toTimeString() method exampleHere, we will understand toTimeString() method through various examples. Example 1Let's see an example to fetch current time in the form of string. <script> var time=new Date(); document.writeln(time.toTimeString()); </script> Output: 10:19:29 GMT+0530 (India Standard Time) Example 2Let's see an example to fetch time portion only from the specified Date object. <script> var time=new Date("August 15, 1947 20:22:10 GMT+0530 (India Standard Time) "); document.writeln(time.toTimeString()); </script> Output: 20:22:10 GMT+0530 (India Standard Time) Example 3Let's see one more example to fetch time portion only from the specified Date object. <script> var time=new Date(1947, 7, 15, 20, 22, 10); document.writeln(time.toTimeString()); </script> Output: 20:22:10 GMT+0530 (India Standard Time)
Next TopicJavaScript Date
|