[英]How to convert time from 24 hour format to 12 hour format using javascript?
[英]jqm-calendar time format (24 hour default…would prefer 12 hour)
我正在为我的jquery移动应用程序使用jqm-calendar。 现在,默认时间格式为24小时。 我想将其更改为12小时。
谢谢。
在文件jw-jqm-cal.js中
添加此功能:
function tConvert (time) {
// Check correct time format and split into components
time = time.toString ().match (/^([01]\d|2[0-3])(:)([0-5]\d)(:[0-5]\d)?$/) || [time];
if (time.length > 1) { // If time format correct
time = time.slice (1); // Remove full string match value
time[5] = +time[0] < 12 ? ' AM' : ' PM'; // Set AM/PM
time[0] = +time[0] % 12 || 12; // Adjust hours
}
return time.join (''); // return adjusted time or original string
}
并在函数plugin.settings.eventHandler.getEventsOnDay(begin,end,function(list_of_events))中 插入 这两 行 :
beginTime =tConvert(beginTime );
endTime=tConvert(endTime);
编辑
在以下位置插入: timeString = beginTime +“-” + endTime:**
...
beginTime = tConvert(beginTime);
endTime = tConvert(endTime);
timeString = beginTime +“-” + endTime,
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.