Yogesh Chauhan's Blog

How to get Current Hour, Minute and Second in JavaScript?

in JavaScript on August 13, 2020

Using JavaScript Date Objects we can get the current hour, minute and second as well as manipulate those numbers.

Get Hour

The getHours() method returns the current hour of any specified date. It will return hour from 0 to 23.

So, we can create a date object first and then using that date we can get the hour.


var d = new Date();
console.log(d.getHours());

// 2

Get Minute

The getMinutes() method returns the current minutes from a date as a number from 0 to 59.

So, similarly like hour, we can create a date object first and then using that date we can get the current minute.


var d = new Date();
console.log(d.getMinutes());

// 8

Get Second

The getSeconds() method returns the second of a date as a number between 0 to 59.

So, similarly like hour and minute, we can create a date object first and then using that date we can get the current second.


var d = new Date();
console.log(d.getSeconds());

// 14

Most Read

#1 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #2 How to add Read More Read Less Button using JavaScript? #3 How to check if radio button is checked or not using JavaScript? #4 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to uninstall Cocoapods from the Mac OS?

Recently Posted

#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface
You might also like these
WordPress: How to set WP_SITEURL?WordPressHow to create a blurry text effect using CSS?CSSHow to vertically and horizontally align text and image block (without flex or grid) in CSS?CSSHow to make a web page look good on any device?HTMLWordPress: How to find all posts from a custom post type with multiple custom fields values?WordPressWordPress: How to setup and get values from an ACF options page?WordPressUseful (and probably ignored) HTML tags: Part 1HTMLHow to zoom an element on hover using CSS?CSSHow to Remove PHP File Extensions From Your Website URLs?PHPHow to remove a specific item from an array in JavaScript?JavaScriptKilling A Project Part 4: What Would Be Your Top 3 Priorities For Planning The Cancellation?MiscellaneousCasting in PostgreSQLPostgres