Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这将是我第一次在我的项目中使用 javascript。我需要将格式为 HH:mm AM/PM 的字符串转换为 24 小时格式 (00:00:00) 时间。请帮助伙计们!先感谢您。
尝试:
var input = '10:23 PM', matches = input.toLowerCase().match(/(\d{1,2}):(\d{2}) ([ap]m)/), output = (parseInt(matches[1]) + (matches[3] == 'pm' ? 12 : 0)) + ':' + matches[2] + ':00'; console.log(output); // 22:23:00