The time type in the query database is Java.sql.Timestamp
Save in JSON requires formatting
Custom Tool Class Datejsonvalueprocessor
1 PackageCom.rom.util;2 3 ImportJava.text.SimpleDateFormat;4 5 Importjava.util.Date;6 ImportJava.util.Locale;7 8 ImportNet.sf.json.JsonConfig;9 ImportNet.sf.json.processors.JsonValueProcessor;Ten One Public classDatejsonvalueprocessorImplementsJsonvalueprocessor { A - PrivateString Datepattern = "Yyyy-mm-dd"; - the Publicdatejsonvalueprocessor () { - Super(); - } - + Publicdatejsonvalueprocessor (String format) { - Super(); + This. Datepattern =format; A } at - PublicObject Processarrayvalue (object value, Jsonconfig jsonconfig) { - returnprocess (value); - } - - PublicObject Processobjectvalue (String key, object value, in jsonconfig Jsonconfig) { - returnprocess (value); to } + - PrivateObject Process (object value) { the Try { * if(ValueinstanceofDate) { $SimpleDateFormat SDF =NewSimpleDateFormat (Datepattern, locale.uk);Panax Notoginseng returnSdf.format ((Date) value); - } the return""; +}Catch(Exception e) { A return""; the } + - } $ $ PublicString Getdatepattern () { - returnDatepattern; - } the - Public voidSetdatepattern (String pdatepattern) {WuyiDatepattern =Pdatepattern; the } - Wu}
The instanceof operator in Java is used to indicate at run time whether an object is an instance of a particular class. Instanceof Indicates whether this object is an instance of this particular class or its subclasses by returning a Boolean value.
usage :
Result = Object Instanceof class
Parameters :
Result: Boolean type.
Object: Required option. An arbitrary object expression.
Class: Required option. Any of the defined object classes.
Description :
If object is an instance of class, the instanceof operator returns TRUE. Returns False if object is not an instance of the specified class, or if object is null.
The colleague who saved the JSON data calls Jsonconfig
1 New jsonconfig (); 2 jsonconfig.registerjsonvalueprocessor (Timestamp. Classnew datejsonvalueprocessor ("Yyyy-mm-dd")); 3 Jsonarray jo = Jsonarray.fromobject (list,jsonconfig);
The program automatically converts the format to java.util.Date form
such as YYYY-MM-DD or YYYY-MM-DD HH:mm:ss
Java.sql.Timestamp in database converted to date