Renderer:function (value) { if (Ext.isempty (value)) {//Determines whether the data of the date type is return '; } else { if (ext.isdate (value)) return Ext.util.Format.date (value, ' y-m-d h:i:s ');//For Time control return value else return value;//converted to date type }} }
1, ExtJS the date of the check---use regular expressions:
var value = "2014-03-03"; var re =/^ (\d{4}) (\/|-) (\d{1,2}) \2 (\d{1,2}) $/var m = re.exec (value); if (M! = null) { var d = New Date (m[1],m[3]-1,m[4]); var falg = d.getfullyear () ==m[1] && d.getmonth () = = (m[3]-1) && d.getdate () ==m[4];} if (value== ' | | | Value.length < 1) { this.msgtarget = "Qtip"; This.invalidtext = ' Required fields cannot be empty! '; return false;} else if (!falg) { this.msgtarget = "Qtip"; This.invalidtext = ' format is incorrect! '; return false;}
2. The processing----ExtJS in the grid list is displayed as Nan
Renderer:function (value) {if(Ext.isempty (value)) {//determine if data is of a date type return "'; } Else { if(Ext.isdate (value))returnExt.util.Format.date (Value,'y-m-d h:i:s');//used for Time control return values Else returnValue//Convert to date type } }}
3, ExtJS calculation date difference:
varIndate = record.Get("indate"); Indate= Indate.replace (/-/g,"/"); Value= Value.replace (/-/g,"/"); varInhours =NewDate (indate); varFinishhours =NewDate (value); varDay = (finishhours-inhours)/( -* -* -* +);//days varHours = (finishhours-inhours)/( -* -* +);//hours if(day>=0&& hours >2){ return '<font color=blue></font><span >'+ Value +'</span>'; }Else{ returnvalue;}
Attached: In case of problem 2, if the background uses Jsonarray to process the object, then you can use the following method:
when using ExtJS, there will be a list to the foreground to put back data, jsonarray processing of the date will be processed into a Date object, in the form of minutes and seconds to deal with;To do this, jsonconfig can be used to process the form of the date;The following method converts the format of a database to a date with a period of minutes or seconds; The data sent to the foreground is a string typeyou can convert it by filling in format with the date you want;in registerjsonvalueprocessor This method, note the date type in the imported database, not the Java one, you can set the first parameter Change to date so String str = new simpledateformat (format). Format ((Timestamp) value);
Jsonconfig Jsonconfig =NewJsonconfig (); Jsonconfig.setexcludes (Newstring[]{"Invoice","Creatorid","modifydate","Modifyid","Modifyname","CreateDate","modifydate","Creatorname"}); Jsonconfig.registerjsonvalueprocessor (Java.sql.Timestamp.class,Newjsonvalueprocessor () {PrivateFinal String format="YYYY-MM-DD"; PublicObject Processobjectvalue (String key, Object Value,jsonconfig arg2) {if(value==NULL) return ""; if(value instanceof Timestamp) {String str=NewSimpleDateFormat (format). Format ((Timestamp) value); returnstr; } returnvalue.tostring (); } PublicObject Processarrayvalue (object value, Jsonconfig arg1) {return NULL; } }); Jsonarray JSON= Jsonarray.fromobject (Inventorylist,jsonconfig);
If the string does not meet your needs, you can write
Package Com.sinosoft.pmhy.util.conver;import Java.util.date;import Org.apache.commons.lang.time.dateformatutils;import Net.sf.json.jsonobject;import Net.sf.json.JsonConfig;import Net.sf.json.processors.JsonBeanProcessor; Public classMyjsdatejsonbeanprocessor implements Jsonbeanprocessor { Public StaticString Default_date_pattern ="YYYY-MM-DD hh:mm"; Public StaticString processdate (date date) {returnDateformatutils.format (date, default_date_pattern); } PrivateString Datepattern =NULL; PublicString Getdatepattern () {if(Datepattern = =NULL) { returnDefault_date_pattern; } Else { returnDatepattern; } } Public voidResetdatepattern () {Datepattern=NULL; } Publicjsonobject Processbean (Object Bean, Jsonconfig jsonconfig) {if(Bean instanceof java.sql.Date) {java.sql.Date d=(java.sql.Date) bean; LongTime =D.gettime (); String pattern=Getdatepattern (); String Date=Dateformatutils.format (time, pattern); returnMakejsonobject (date, time, pattern); } if(bean instanceof date) {Date D=(Date) bean; LongTime =D.gettime (); String pattern=Getdatepattern (); String Date=Dateformatutils.format (time, pattern); returnMakejsonobject (date, time, pattern); } return NewJsonobject (true); } Private StaticJsonobject Makejsonobject (String date,LongTime , String pattern) {Jsonobject Jsonobject=NewJsonobject (); Jsonobject.element ("Date", date); Jsonobject.element (" Time", time); Jsonobject.element ("pattern", pattern); returnJsonobject; }}
This conversion time can meet the date, and the time of the acquisition
The processing of dates in ExtJS