YogeshChauhan . com

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
amazon

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 How to Use SQL MAX() Function with Dates? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

Jun 16 What are Stored Procedures for SQL Server? Jun 16 What are Class Constants in PHP? Jun 15 A short basic guide on states in React Jun 15 How to define constants in PHP? Jun 15 How to define visibility for a property in PHP? Jun 15 How to use @if and @else in SCSS?

You might also like these

How To Create a Fullscreen Background Video using CSS and JavaScript?CSSLearn how to give a temporary name to a column or to a table using SQL AliasesSQL/MySQLIntroduction to Angular modules Part 2: NgModules and componentsAngularHow to swap images on hover using CSS?CSSHow to add a scroll back to top button using JavaScript and CSS?CSSRIGHT JOIN in PostgresPostgresUNION and UNION ALL in PostgresPostgresAn Example of Cross-site Scripting (XSS) Attack in PHP and How to Avoid It?PHPCREATE DATABASE in PostgreSQLPostgresWordPress: How to get ACF field values from another post?WordPressLearn to Implement Estimated Reading Time using PHP Part 1: The BasicsPHPFor Each Loop in Swift for BeginnersSwift