0

这将是我第一次在我的项目中使用 javascript。我需要将格式为 HH:mm AM/PM 的字符串转换为 24 小时格式 (00:00:00) 时间。请帮助伙计们!先感谢您。

4

1 回答 1

1

尝试:

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 
于 2013-12-18T10:08:35.213 回答