简体   繁体   中英

jqm-calendar time format (24 hour default…would prefer 12 hour)

I am using jqm-calendar for my jquery mobile app. Right now the default time format is 24 hours. I would like to change it to 12 hours.

Thank you.

https://github.com/JWGmeligMeyling/jqm-calendar

In file jw-jqm-cal.js

add this function:

  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
}

and insert this 2 lines in function plugin.settings.eventHandler.getEventsOnDay(begin, end, function(list_of_events) :

beginTime =tConvert(beginTime );
endTime=tConvert(endTime);

EDIT

insert before: timeString = beginTime + "-" + endTime :**

...

beginTime =tConvert(beginTime );

endTime=tConvert(endTime);

timeString = beginTime + "-" + endTime,

...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM