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 Overflow
🌐
GeeksforGeeks
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)....
🌐
W3Resource
w3resource.com › javascript-exercises › javascript-date-exercise-34.php
JavaScript: Get 24-hour format of an hour without leading zeros - w3resource
Write a JavaScript function that extracts the hour from a Date object and returns it in 24-hour format as a number. Write a JavaScript function that converts a 12-hour time string with AM/PM into 24-hour time without leading zeros.
🌐
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.
🌐
Medium
medium.com › front-end-weekly › how-to-convert-24-hours-format-to-12-hours-in-javascript-ca19dfd7419d
How to convert 24 hours format to 12 hours in Javascript.
November 10, 2019 - var dt = new Date();var hours = dt.getHours(); // gives the value in 24 hours formatvar minutes = dt.getMinutes() ; var finalTime = "Time - " + hours + ":" + minutes; finalTime // final time Time - 22:10
🌐
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 ...
Find elsewhere
🌐
SheCodes
shecodes.io › athena › 8026-how-to-display-the-current-time-in-javascript
[JavaScript] - How to Display the Current Time in | SheCodes
Learn how to create a clock using HTML, CSS, and JavaScript to display the current time in 24-hour format
🌐
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.
🌐
RSWP Themes
rswpthemes.com › home › javascript tutorial › how to get current time in 24-hour format in javascript
How to Get Current Time in 24-Hour Format in JavaScript
December 20, 2023 - In this article, we explored different methods to obtain the current time in the 24-hour format using JavaScript. We discussed using built-in methods like toLocaleTimeString(), as well as manually extracting hour and minute components using getHours() and getMinutes().
🌐
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 ?
🌐
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 ...
🌐
The Web Dev
thewebdev.info › home › how to format moment.js as a 24-hour format date-time?
How to Format Moment.js as a 24-Hour Format Date-Time? - The Web Dev
April 27, 2021 - Alternatively, we can use the H formatting tag to format the hour to 24-hour format. ... We can use the H or HH formatting tag to format the hour of a date-time as a 24-hour format time.