A common question that is asked many times by javascript developers is how to get the current time in javascript.

Sometimes, we need to get the current time because we want to perform some actions based on the time of the day.

Fortunately, getting the current time in javascript is very easy and in this blog post, we will learn that.



Get Current Time In Javascript Using new Date()

In javascript, we can use the Date() object to get the current date of the client machine it is running on and then use this date to get the time information from it.

Let's use this in an example and get the hours, minutes and seconds from date in javascript.





Get current time in javascript


As we can see in the example above, if we use the new Date() object we have access to a lot of methods that returns us date and time.

Using the same technique, you can get the current hours, current minutes and current seconds and can format it according to your liking.