Categories
JavaScript Answers

How to show current time in JavaScript in the format HH:MM:SS?

Spread the love

Sometimes, we want to show current time in JavaScript in the format HH:MM:SS.

In this article, we’ll look at how to show current time in JavaScript in the format HH:MM:SS.

How to show current time in JavaScript in the format HH:MM:SS?

To show current time in JavaScript in the format HH:MM:SS, we use the date’s toLocaleTimeString method.

For instance, we write

const d = new Date();
console.log(d.toLocaleTimeString());

to create date d with the current datetime.

And we call toLocaleTimeString to return a string with the human readable locale time string with date and time being the values in d.

Conclusion

To show current time in JavaScript in the format HH:MM:SS, we use the date’s toLocaleTimeString method.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *