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
}
Answer from SheetJS on Stack OverflowGeeksforGeeks
geeksforgeeks.org › javascript › javascript-program-to-convert-string-to-24-hour-time-format
JavaScript Program to Convert String to 24-hour Time Format - GeeksforGeeks
July 23, 2025 - We are going to learn about the ... to a 24-hour time format involves transforming a time representation from the traditional 12-hour clock (AM/PM) to the 24-hour clock (00:00 to 23:59)....
Top answer 1 of 2
40
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
}
2 of 2
6
In moment.js you can do:
theDate.format("H:MM")
Take a look here for more details: http://blog.stevenlevithan.com/archives/date-time-format
Videos
08:19
How to Create a Digital Clock Using JavaScript | Real-Time Clock ...
01:24
How to Change Date to 24 Hour Format in JavaScript - YouTube
14:20
JavaScript 12/24-Hour Digital Clock - Coding Tutorials by Umar ...
How to convert 24hr time to 12hr time format in JavaScript ...
03:14
How to Format Time as HH:MM:SS from a Date in JavaScript - YouTube
TutorialsPoint
tutorialspoint.com › article › converting-12-hour-format-time-to-24-hour-format-in-javascript
Converting 12 hour Format Time to 24 hour Format in JavaScript
To convert 12 hour format to 24 hour format in JavaScript we have used string manipulation method where, we have used split() method to separate the time and modifier and then hour and minutes along with if/else statement to adjust hour value.
Top answer 1 of 15
73
use dateObj.toLocaleString([locales[, options]])
Option 1 - Using locales
var date = new Date();
console.log(date.toLocaleString('en-GB'));
Option 2 - Using options
var options = { hour12: false };
console.log(date.toLocaleString('en-US', options));
2 of 15
22
hourCycle: 'h23' is Perfect
Thanks to https://stackoverflow.com/users/12425695/luis-serrano
new Date().toLocaleString('ru-RU', {
timeZone: 'Europe/Moscow',
hourCycle: 'h23',
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit"
});
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › toLocaleTimeString
Date.prototype.toLocaleTimeString() - JavaScript | MDN
const date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0)); // formats below assume the local time zone of the locale; // America/Los_Angeles for the US // US English uses 12-hour time with AM/PM console.log(date.toLocaleTimeString("en-US")); // "7:00:00 PM" // British English uses 24-hour time ...
Plain English
plainenglish.io › blog › javascript-tutorial-convert-time-am-pm-to-24-hours-7a1bb69b20a
Convert Time From AM/PM to 24-Hour Format Using JavaScript
This time I just want to share the JavaScript code on how to convert am or pm time to 24 hours, hopefully, this tutorial is useful for all of you. Okay, let’s just go to the tutorial this time. var hrs = Number(timestart.match(/^(\d+)/)[1]); var mnts = Number(timestart.match(/:(\d+)/)[1]); var format = timestart.match(/\s(.*)$/)[1]; if (format == "PM" && hrs < 12) hrs = hrs + 12; if (format == "AM" && hrs == 12) hrs = hrs - 12; var hours = hrs.toString(); var minutes = mnts.toString(); if (hrs < 10) hours = "0" + hours; if (mnts < 10) minutes = "0" + minutes; var timeend = hours + ":" + minutes + ":00"; console.log(timeend); //h:i:s
Clue Mediator
cluemediator.com › convert-a-12-hour-format-to-24-hour-format-using-javascript
Convert a 12 hour format to 24 hour format using JavaScript - Clue Mediator
Use the following JavaScript code to get the converted time. var convertedTime = moment("01:00 PM", 'hh:mm A').format('HH:mm') console.log(convertedTime); // Output: 13:00 · In the second method, we’ll use the following custom JavaScript function to convert the 12 hour format to 24 hour format.
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › HTML › Element › input › time
<input type="time"> - HTML | MDN
You can also get and set the time value in JavaScript using the HTMLInputElement value property, for example: ... The value of the time input is always in 24-hour format that includes leading zeros: HH:mm, regardless of the input format, which is likely to be selected based on the user's locale ...
GitHub
github.com › moment › moment › issues › 2959
Covert to 24 hours time formate · Issue #2959 · moment/moment
February 11, 2016 - var start_time = $('.start_time').val(); this will return time like 02:00 PM How can I convert it 24 hours time format using moment js. I used this plugin to show time.
Author iamkallolpratim
Mikesdotnetting
mikesdotnetting.com › article › 32 › javascript-24-hour-clock
Javascript 24 hour clock
<script type="text/javascript"> var tick; function stop() { clearTimeout(tick); } function clock() { var ut=new Date(); var h,m,s; var time=" "; h=ut.getHours(); m=ut.getMinutes(); s=ut.getSeconds(); if(s<=9) s="0"+s; if(m<=9) m="0"+m; if(h<=9) h="0"+h; time+=h+":"+m+":"+s; document.getElementById('clock').innerHTML=time; tick=setTimeout("clock()",1000); } </script> <body onload="clock();" onunload="stop();">
Sololearn
sololearn.com › en › Discuss › 2865424 › is-there-any-shortcut-way-to-convert-24-hour-format-to-12-hour-format-with-am-pm-in-javascript
❝Is there any shortcut way to convert 24 hour format to 12 hour format (with am & pm) in JavaScript?❞ | Sololearn: Learn to code for FREE!
"0" + s : s; /* if you want 2 digit hours: h = h<10?"0"+h:h; */ var pattern = new RegExp("0?" + hh + ":" + m + ":" + s); var replacement = h + ":" + m; /* if you want to add seconds replacement += ":"+s; */ replacement += " " + dd; return date.replace(pattern, replacement); } alert(formatDate("February 04, 2011 12:00:00")); ... Vadivelan I used this↓ if (hr>11){ sec=sec+'<span style="font-size: 6vw;"> PM</span>' } else { sec=sec+'<span style="font-size: 6vw;"> AM</span>' } ... yes there is https://code.sololearn.com/WTkSrXL2rb4d/?ref=app function addZero(x){ return x < 10 ? "0"+String(x) : String(x); } //24-Hour Format var date = new Date(); var hours = addZero(date.getHours()); var newformat = hours >= 12 ?
Top answer 1 of 9
558
Stating your time as HH will give you 24h format, and hh will give 12h format.
You can also find it here in the documentation :
H, HH 24 hour time
h, or hh 12 hour time (use in conjunction with a or A)
2 of 9
51
moment("01:15:00 PM", "h:mm:ss A").format("HH:mm:ss")
**o/p: 13:15:00 **
It will convert 12hrs format to 24hrs format.
JSFiddle
jsfiddle.net › gengns › xcgjz9xt
HTML input time with 24 hours format - JSFiddle - Code Playground
We do and so much of JSFiddle was still dependant on it till this day, but since almost all MooTools features are now available in native JS it was high-time to strip it out of the codebase.
Webdevtutor
webdevtutor.net › blog › javascript-date-format-24-hours
How to Format Dates in JavaScript Using 24-Hour Time
Here's a simple example: javascript const date = new Date(); const formatter = new Intl.DateTimeFormat('en-US', { hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false }); const formattedTime = formatter.format(date); console.log(formattedTime); // Output: "14:30:15" In the code ...