This post will discuss how to find the current time without date in JavaScript.

There are several ways to find the current time without the date in JavaScript. A time without the date is a time that only contains the hours, minutes, and seconds, and ignores the year, month, and day. Here are some of the common functions:

1. Using Date.prototype.toLocaleTimeString() function

The Date.prototype.toLocaleTimeString() function returns a string with a language-sensitive representation of the time portion of a date object. It takes an optional locale parameter and an optional options parameter that can specify the hour, minute, second, and time zone format. This function works well for displaying the current time in a human-readable way. For instance:

Download  Run Code

2. Using Date.prototype.toTimeString() function

We can use the Date.prototype.toTimeString() function to get the current time as a human-readable string in the default time zone. This function returns a string with the time portion of a date object, followed by the time zone offset in parentheses. It does not take any parameters and it always uses 24-hour format. We can further use the slice() function to extract only the time part of the returned string, which will be in HH:MM:SS format. For instance:

Download  Run Code

3. Using Date.prototype.get*() functions

We can use Date.prototype.getHours(), Date.prototype.getMinutes(), and Date.prototype.getSeconds() built-in functions that return the hour, minute, and second components of a date object, respectively. They do not take any parameters and they always use 24-hour format. We can use these functions to get the individual components of the time and format them as we like. For instance:

Download  Run Code

That’s all about finding the current time without date in JavaScript.