我有文本输入来输入时间,有时当我双击输入时我需要将时间从 12 小时格式更改为 24 格式.. 所以我怎样才能像这样转换时间:
1:00 => 13:00
01:00 => 13:00
(提示)我的代码:
$("input").live('dblclick', function(){
var type12 = $(this).val();
if (type12.length == 4){
var time = type12.replace(/\:/, '');
var hh = time.substr(0,1);
var mm = time.substr(0,3); // TO DO
var type24 = Number(hh) + 12;
var time24 = hh + mm;
$(this).val(time24);
sortTimes($(this).closest("tr"));
}else{alert('not');}
});