EasyUI Forum
May 09, 2024, 01:17:43 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: Datetimebox format - day/month/year HH:MM:SS  (Read 12733 times)
A-K
Full Member
***
Posts: 122


View Profile WWW
« on: July 20, 2014, 12:22:52 PM »

Hey,
Im trying to change how the date is shown in the datetimebox but I have a few problems,
As I have noticed when I created the formatter and created the format above it didnt work and when I checked why I saw
that easyui tries to parse the string he gets from the formatter and since the Date() in js doesnt know how to parse it
it just return new Date() in the end. So i overrided the parse function but then I found a problem that I cant create a date with UTC + 2.

Any help with this will be much appreciated.

Thanks, Alon.
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #1 on: July 20, 2014, 05:48:08 PM »

The simple implementation to parse 'day/month/year HH:MM:SS' datetime format shows as below:
Code:
$('#dt').datetimebox({
  formatter:function(date){
    var s1 = [date.getDate(),date.getMonth()+1,date.getFullYear()].join('/');
    var s2 = [date.getHours(),date.getMinutes(),date.getSeconds()].join(':');
    return s1 + ' ' + s2;
  },
  parser:function(s){
    if (!s){return new Date();}
    var dt = s.split(' ');
    var date = new Date(dt[0][2],dt[0][1],dt[0][0]);
    if (dt.length>1){
      date.setHours(dt[1][0]);
      date.setMinutes(dt[1][1]);
      date.setSeconds(dt[1][2]);
    }
    return date;
  }
})
Logged
A-K
Full Member
***
Posts: 122


View Profile WWW
« Reply #2 on: July 21, 2014, 06:44:33 AM »

The simple implementation to parse 'day/month/year HH:MM:SS' datetime format shows as below:
Code:
$('#dt').datetimebox({
  formatter:function(date){
    var s1 = [date.getDate(),date.getMonth()+1,date.getFullYear()].join('/');
    var s2 = [date.getHours(),date.getMinutes(),date.getSeconds()].join(':');
    return s1 + ' ' + s2;
  },
  parser:function(s){
    if (!s){return new Date();}
    var dt = s.split(' ');
    var date = new Date(dt[0][2],dt[0][1],dt[0][0]);
    if (dt.length>1){
      date.setHours(dt[1][0]);
      date.setMinutes(dt[1][1]);
      date.setSeconds(dt[1][2]);
    }
    return date;
  }
})

Thanks so much for the answer! It helped a lot!
I would like to add a little fix to the code above because it didnt work right away
In the parser there should be another 2 splits and the parser should look like this:

parser:function(s){
    if (!s){return new Date();}
    var dt = s.split(' ');
    var dateFormat = dt[0].split('/');
    var timeFormat = dt[1].split(':');
    var date = new Date(dateFormat[2],dateFormat[1],dateFormat[0]);
    if (dt.length>1){
      date.setHours(timeFormat[0]);
      date.setMinutes(timeFormat[1]);
      date.setSeconds(timeFormat[2]);
    }
    return date;
  }

Then everything works just fine!
Thanks.
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!