package cn.jbit.BookSys.util; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import net.sf.json.JsonConfig; import net.sf.json.processors.JsonValueProcessor; public class JsonDateValueProcessor implements JsonValueProcessor{ private String format ="yyyy-MM-dd"; public JsonDateValueProcessor() { super(); } public JsonDateValueProcessor(String format) { super(); this.format = format; } @Override public Object processArrayValue(Object value, JsonConfig jsonConfig) { // TODO Auto-generated method stub String[] obj = {}; if (value instanceof Date[]) { SimpleDateFormat sf = new SimpleDateFormat(format); Date[] dates = (Date[]) value; obj = new String[dates.length]; for (int i = 0; i < dates.length; i++) { obj[i] = sf.format(dates[i]); } } return obj; } @Override public Object processObjectValue(String key, Object value, JsonConfig jsonConfig) { // TODO Auto-generated method stub if (value instanceof Date) { String str = new SimpleDateFormat(format).format((Date) value); return str; } return value; } public String getFormat() { return format; } public void setFormat(String format) { this.format = format; } }
时间: 2024-11-05 13:51:23