After Response.getwriter (). Write (JSON) to the foreground date format confusing problem summary
Import Java.text.SimpleDateFormat;
Import Net.sf.json.JsonConfig;
Import Net.sf.json.processors.JsonValueProcessor;
public class Datejsonvalueprocessor implements Jsonvalueprocessor
{
Private String format;
Public datejsonvalueprocessor (String format) {
This.format = format;
}
public object Processarrayvalue (object value, Jsonconfig jsonconfig)
{
return null;
}
Public Object Processobjectvalue (String key, object value, Jsonconfig jsonconfig)
{
if (value = = null)
{
return "";
}
if (value instanceof Java.sql.Timestamp)
{
String str = new SimpleDateFormat (format). Format ((java.sql.Timestamp) value);
return str;
}
if (value instanceof java.util.Date)
{
String str = new SimpleDateFormat (format). Format ((java.util.Date) value);
return str;
}
return value.tostring ();
}
}
Date issues in the daily development process often encounter the problem of format mismatch, but the general solution is relatively single, as long as find the right method, I believe it can be quickly resolved!!! Good luck!!!!
Tool class: About resolving date formats in the database, passing Response.getwriter (). Write (JSON) to the foreground date format confusing problem summary