![](/img/trans.png)
[英]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.