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();

// 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();

// 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();

// 14

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Aug 15 Is PHP still good for back-end programming? #Aug 10 How to create a multisite network in WordPress? #Aug 3 How to create a circle that follows a cursor using JavaScript and CSS? #Aug 3 How to make a curtain slider using jQuery and CSS? #Aug 2 How to progressively load images and add a blurry placeholder? #Aug 1 How to create a placeholder loader (throbber) using CSS?
You might also like these
Order By and Group By in PostgresPostgresKubernetes vs. Docker? It’s a misleading phraseMiscellaneousSQL GROUP BY StatementSQL/MySQLHow to make a Custom Login Page in WordPress?WordPressHow Do You Make a Private VPN?MiscellaneousCONCAT and CONCAT_WS Functions in PostgresPostgresThe difference between isFinite() method and isFinite() function in JavaScriptJavaScriptLearn to create your skill bar using CSSCSSHow to set opacity or transparency using CSS?CSSWhat are Controlled Components in React?ReactHow to define variables in SCSS (Sass)?SCSSHow to obfuscate JavaScript code to hide it from View Source?JavaScript