我有这个代码,但它不起作用。我如何检查时间是在AM还是PM。
var time = $(id1).val();
var hrs = Number(time.match(/^(\d+)/)[1]);
var mnts = Number(time.match(/:(\d+)/)[1]);
var format = time.match(/\s(.*)$/);
//alert(format);
//alert(time);
if (format == "PM" && hrs < 12) {
hrs = hrs + 12;
}
if (format == "AM" && hrs == 12) hrs = hrs - 12;
答案 0 :(得分:0)
你从三年前的答案(convert 12-hour hh:mm AM/PM to 24-hour hh:mm)
中犯了一个复制/粘贴错误var format = time.match(/\s(.*)$/)[1];
不要忘记[1]