EasyUI Forum
April 20, 2024, 01:54:26 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Easyui Default date format to dd.mm.yyyy  (Read 5707 times)
Alfred
Full Member
***
Posts: 134


-Licensed User-


View Profile
« on: April 17, 2018, 10:34:26 AM »

I found the following codes to override easyui default date format. Instead of using forward slash I want to use .(period) to separate the day, month and year. So I change the forwardslash with period(.). The problem is that I could not select the other dates other than the current date from the date pickup.

Code:
$.extend($.fn.datebox.defaults,{
    formatter:function(date){
        var y = date.getFullYear();
        var m = date.getMonth()+1;
        var d = date.getDate();
        return (d<10?('0'+d):d)+'/'+(m<10?('0'+m):m)+'/'+y;
       //(d<10?('0'+d):d)+'.'+(m<10?('0'+m):m)+'.'+y; this works but would not allow me to choose other dates
    },
    parser:function(s){
        if (!s) return new Date();
        var ss = s.split('/');
        var d = parseInt(ss[0],10);
        var m = parseInt(ss[1],10);
        var y = parseInt(ss[2],10);
        if (!isNaN(y) && !isNaN(m) && !isNaN(d)){
            return new Date(y,m-1,d);
        } else {
            return new Date();
        }
    }
});
I could not figure out what else must be changed in the codes to make it work.
Thanks.
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #1 on: April 17, 2018, 06:30:02 PM »

The code should be:
Code:
$.extend($.fn.datebox.defaults,{
    formatter:function(date){
        var y = date.getFullYear();
        var m = date.getMonth()+1;
        var d = date.getDate();
        return (d<10?('0'+d):d)+'.'+(m<10?('0'+m):m)+'.'+y;
    },
    parser:function(s){
        if (!s) return new Date();
        var ss = s.split('\.');
        var d = parseInt(ss[0],10);
        var m = parseInt(ss[1],10);
        var y = parseInt(ss[2],10);
        if (!isNaN(y) && !isNaN(m) && !isNaN(d)){
            return new Date(y,m-1,d);
        } else {
            return new Date();
        }
    }
});
Logged
Alfred
Full Member
***
Posts: 134


-Licensed User-


View Profile
« Reply #2 on: April 17, 2018, 08:11:42 PM »

Thank very much, this works.
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!