本文整理汇总了Java中com.alibaba.fastjson.JSON.DEFFAULT_DATE_FORMAT属性的典型用法代码示例。如果您正苦于以下问题:Java JSON.DEFFAULT_DATE_FORMAT属性的具体用法?Java JSON.DEFFAULT_DATE_FORMAT怎么用?Java JSON.DEFFAULT_DATE_FORMAT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.alibaba.fastjson.JSON
的用法示例。
在下文中一共展示了JSON.DEFFAULT_DATE_FORMAT属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: write
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType,
int features) throws IOException {
SerializeWriter out = serializer.out;
if (object == null) {
out.writeNull();
} else {
if (fieldType == null) {
fieldType = object.getClass();
}
if (fieldType == LocalDateTime.class) {
final int mask = SerializerFeature.UseISO8601DateFormat.getMask();
LocalDateTime dateTime = (LocalDateTime) object;
String format = serializer.getDateFormatPattern();
if (format == null && (features & mask) != 0 || serializer.isEnabled(SerializerFeature.UseISO8601DateFormat)) {
format = formatter_iso8601_pattern;
}
if (dateTime.getNano() == 0 || format != null) {
if (format == null) {
format = JSON.DEFFAULT_DATE_FORMAT;
}
write(out, dateTime, format);
} else if (out.isEnabled(SerializerFeature.WriteDateUseDateFormat)) {
//使用固定格式转化时间
write(out, dateTime, JSON.DEFFAULT_DATE_FORMAT);
} else {
out.writeLong(dateTime.atZone(JSON.defaultTimeZone.toZoneId()).toInstant().toEpochMilli());
}
} else {
out.writeString(object.toString());
}
}
}
示例2: test_castToDate
public void test_castToDate() throws Exception {
JSON.DEFFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS";
Date date = TypeUtils.castToDate("2012-07-15 12:12:11");
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
format.setTimeZone(JSON.defaultTimeZone);
Assert.assertEquals(format.parseObject("2012-07-15 12:12:11"), date);
JSON.DEFFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
}
示例3: test_for_issue_1
public void test_for_issue_1() throws Exception {
JSON.DEFFAULT_DATE_FORMAT = "yyyyMMddHHmmssSSSZ";
String json = "{\"value\":\"20180131022733000-0800\"}";
JSONObject object = JSON.parseObject(json);
object.getObject("value", Date.class);
JSON.DEFFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
}
示例4: test_0
public void test_0 () throws Exception {
long millis = (System.currentTimeMillis() / 1000) * 1000;
SimpleDateFormat format = new SimpleDateFormat(JSON.DEFFAULT_DATE_FORMAT, JSON.defaultLocale);
format.setTimeZone(JSON.defaultTimeZone);
String text = "\"" + format.format(new Date(millis)) + "\"";
System.out.println(text);
Assert.assertEquals(new Timestamp(millis), JSON.parseObject("" + millis, Timestamp.class));
Assert.assertEquals(new Timestamp(millis), JSON.parseObject("\"" + millis + "\"", Timestamp.class));
Assert.assertEquals(new Timestamp(millis), JSON.parseObject(text, Timestamp.class));
Assert.assertEquals(new java.sql.Date(millis), JSON.parseObject(text, java.sql.Date.class));
Assert.assertEquals(new java.util.Date(millis), JSON.parseObject(text, java.util.Date.class));
}
示例5: test_for_xiayucai2012
public void test_for_xiayucai2012() throws Exception {
String text = "{\"date\":\"0000-00-00 00:00:00\"}";
JSONObject json = JSON.parseObject(text);
Date date = json.getObject("date", Date.class);
SimpleDateFormat dateFormat = new SimpleDateFormat(JSON.DEFFAULT_DATE_FORMAT, JSON.defaultLocale);
dateFormat.setTimeZone(JSON.defaultTimeZone);
Assert.assertEquals(dateFormat.parse(json.getString("date")), date);
}
示例6: DefaultJSONParser
public DefaultJSONParser(Object input, JSONLexer lexer, ParserConfig config) {
this.dateFormatPattern = JSON.DEFFAULT_DATE_FORMAT;
this.contextArray = new ParseContext[8];
this.contextArrayIndex = 0;
this.resolveStatus = 0;
this.extraTypeProviders = null;
this.extraProcessors = null;
this.lexer = lexer;
this.input = input;
this.config = config;
this.symbolTable = config.getSymbolTable();
lexer.nextToken(12);
}
示例7: test_for_issue
public void test_for_issue() throws Exception {
JSON.DEFFAULT_DATE_FORMAT = "yyyyMMddHHmmssSSSZ";
String json = "{\"value\":\"20180131022733000-0800\"}";
JSON.parseObject(json, Model.class);
JSON.DEFFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
}
示例8: serializer
@Override
public <T> byte[] serializer(T obj) {
JSON.DEFFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
return JSON.toJSONBytes(obj, SerializerFeature.WriteDateUseDateFormat);
}
示例9: castToDate
public static final Date castToDate(Object value) {
if (value == null) {
return null;
}
if (value instanceof Calendar) {
return ((Calendar) value).getTime();
}
if (value instanceof Date) {
return (Date) value;
}
long j = -1;
if (value instanceof Number) {
j = ((Number) value).longValue();
}
if (value instanceof String) {
String strVal = (String) value;
if (strVal.indexOf(45) != -1) {
String format;
if (strVal.length() == JSON.DEFFAULT_DATE_FORMAT.length()) {
format = JSON.DEFFAULT_DATE_FORMAT;
} else if (strVal.length() == 10) {
format = "yyyy-MM-dd";
} else if (strVal.length() == "yyyy-MM-dd HH:mm:ss".length()) {
format = "yyyy-MM-dd HH:mm:ss";
} else {
format = "yyyy-MM-dd HH:mm:ss.SSS";
}
try {
return new SimpleDateFormat(format).parse(strVal);
} catch (ParseException e) {
throw new JSONException("can not cast to Date, value : " + strVal);
}
} else if (strVal.length() == 0) {
return null;
} else {
j = Long.parseLong(strVal);
}
}
if (j >= 0) {
return new Date(j);
}
throw new JSONException("can not cast to Date, value : " + value);
}
示例10: castToDate
public static final Date castToDate(Object value) {
if (value == null) {
return null;
}
if (value instanceof Calendar) {
return ((Calendar) value).getTime();
}
if (value instanceof Date) {
return (Date) value;
}
long longValue = -1;
if (value instanceof Number) {
longValue = ((Number) value).longValue();
return new Date(longValue);
}
if (value instanceof String) {
String strVal = (String) value;
if (strVal.indexOf('-') != -1) {
String format;
if (strVal.length() == JSON.DEFFAULT_DATE_FORMAT.length()) {
format = JSON.DEFFAULT_DATE_FORMAT;
} else if (strVal.length() == 10) {
format = "yyyy-MM-dd";
} else if (strVal.length() == "yyyy-MM-dd HH:mm:ss".length()) {
format = "yyyy-MM-dd HH:mm:ss";
} else {
format = "yyyy-MM-dd HH:mm:ss.SSS";
}
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
try {
return (Date) dateFormat.parse(strVal);
} catch (ParseException e) {
throw new JSONException("can not cast to Date, value : " + strVal);
}
}
if (strVal.length() == 0) {
return null;
}
longValue = Long.parseLong(strVal);
}
if (longValue < 0) {
throw new JSONException("can not cast to Date, value : " + value);
}
return new Date(longValue);
}