Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert time to 24 hours format in Javascript [closed]

How can I isolate and convert the local time format in JavaScript's new Date() to a 24 hour format?

Example: 2016-09-22T23:21:56.027Z just becomes 22:56 in local time.

like image 342
Kishh Avatar asked Nov 24 '09 08:11

Kishh


People also ask

How do you get time in 24 hour format?

let dt = moment(); dt. format(“HH:mm”) // 24 hour time.

How do I convert 24 hours to 12 hours in react JS?

Convert the 24 hours format time to 12 hours formatted time. Now in-order to convert it to 12 hours format you can take % 12 on the current time. time = 24, then 24%12 → 0 , if the time is 0, then change the time as 12.

What is HH MM 24 hour format?

A time of day is written in the 24-hour notation in the form hh:mm (for example 01:23) or hh:mm:ss (for example, 01:23:45), where hh (00 to 23) is the number of full hours that have passed since midnight, mm (00 to 59) is the number of full minutes that have passed since the last full hour, and ss (00 to 59) is the ...


2 Answers

new Date("2000-01-01 10:30 AM").getHours() // 10 

This is 24 hours:

new Date("2000-01-01 10:30 PM").getHours() // 22 

If you want a more general thing:

function get_hours(time_string) {     return new Date("2000-01-01 " + time_string).getHours() // 22 } 
like image 62
SheetJS Avatar answered Oct 23 '22 07:10

SheetJS


theDate.format("H:MM") 

Take a look here for more details: http://blog.stevenlevithan.com/archives/date-time-format

like image 44
Konamiman Avatar answered Oct 23 '22 08:10

Konamiman