Title: way for datetimebox to use am/pm instead of 24-hour display?
Post by: tomhj on May 30, 2013, 02:23:25 PM
Non-military users often don't like having to convert 4pm to 16:00, for instance.
Is there a way to configure datetimebox to use am/pm instead of the 24-hour display?
thanks, Tom
Title: Re: way for datetimebox to use am/pm instead of 24-hour display?
Post by: stworthy on May 30, 2013, 07:41:45 PM
Try to override the 'formatter' and 'parser' of datetimebox. $.extend($.fn.datetimebox.defaults,{ formatter:function(date){ var h = date.getHours(); var M = date.getMinutes(); var s = date.getSeconds(); var ampm = h >= 12 ? 'pm' : 'am'; h = h % 12; h = h ? h : 12; function formatNumber(value){ return (value < 10 ? '0' : '') + value; } var separator = $(this).datetimebox('spinner').timespinner('options').separator; var r = $.fn.datebox.defaults.formatter(date) + ' ' + formatNumber(h)+separator+formatNumber(M); if ($(this).datetimebox('options').showSeconds){ r += separator+formatNumber(s); } r += ' ' + ampm; return r; }, parser:function(s){ if ($.trim(s) == ''){ return new Date(); } var dt = s.split(' '); var d = $.fn.datebox.defaults.parser(dt[0]); if (dt.length < 2){ return d; } var separator = $(this).datetimebox('spinner').timespinner('options').separator; var tt = dt[1].split(separator); var hour = parseInt(tt[0], 10) || 0; var minute = parseInt(tt[1], 10) || 0; var second = parseInt(tt[2], 10) || 0; var ampm = dt[2]; if (ampm == 'pm'){ hour += 12; } return new Date(d.getFullYear(), d.getMonth(), d.getDate(), hour, minute, second); } });
Title: Re: way for datetimebox to use am/pm instead of 24-hour display?
Post by: tomhj on June 03, 2013, 11:19:12 PM
Thanks - that is pretty close to what I need. But the timespinner shown at the bottom of the drop down calendar still shows the hour spinner going 0-23. Any way to change that to 1-12 with another spinner for am/pm?
|