EasyUI Forum
April 25, 2024, 04:57:40 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: way for datetimebox to use am/pm instead of 24-hour display?  (Read 10556 times)
tomhj
Newbie
*
Posts: 40


View Profile
« 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
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: May 30, 2013, 07:41:45 PM »

Try to override the 'formatter' and 'parser' of datetimebox.
Code:
	$.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);
}
});
Logged
tomhj
Newbie
*
Posts: 40


View Profile
« Reply #2 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?
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!