JavaScript time format | Short and Simple examples

To get the time or date in JS you have to use the getTime() method but returns the number of milliseconds* since the Unix Epoch. You have to use getHours(), getMinutes() and getSeconds() to get desired time format in JavaScript.

Note: JavaScript uses millisecondsas the unit of measurement, whereas Unix Time is in seconds.

Short and simple:

Complete code

Example of JavaScript time format

It’s a very easy, Let’s see complete html code:-


avaScript time format

Get and set the current time efficiently using javascript


USE: toLocaleTimeString

Present browser support to simply use: toLocaleTimeString For HTML 5 type time the format must be HH:MM.

Do comment if you have any doubts, questions and suggestions on this topic.

Note: The All JS Examples codes are tested on the Safari browser (Version 12.0.2) and Chrome.
OS: macOS 10.14 Mojave
Code: HTML 5 Version

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.