Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hour format in javascript

Tags:

javascript

In my javascript iam using GetHour and GetMinutes function.For eg:Current Time is 2:03.If in this case i use GetHour(),it returns 2.Instead i need 02.Can anybody help?

like image 778
user42348 Avatar asked Apr 27 '09 08:04

user42348


People also ask

How do you write hours in JavaScript?

To get the hours and minutes from a date, call the getHours() and getMinutes() methods on the date object. The getHours method returns the hours and the getMinutes() method returns the minutes in the specified date.

What is the time format in JavaScript?

The string format should be: YYYY-MM-DDTHH:mm:ss. sssZ , where: YYYY-MM-DD – is the date: year-month-day. The character "T" is used as the delimiter.

How do you display JavaScript datetime in 24 hour format?

Use the toLocaleString() method to change time formatting to 24 hours, e.g. date. toLocaleString('en-US', {hour12: false}) . The toLocaleString method returns a string that represents the date and time according to the provided locale and options parameters.


1 Answers

var hour = GetHour() < 10 ? '0' + GetHour() : GetHour();
like image 122
Greg Avatar answered Oct 10 '22 03:10

Greg