本文整理汇总了Java中com.alibaba.fastjson.parser.DefaultJSONParser.getDateFormat方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultJSONParser.getDateFormat方法的具体用法?Java DefaultJSONParser.getDateFormat怎么用?Java DefaultJSONParser.getDateFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.fastjson.parser.DefaultJSONParser
的用法示例。
在下文中一共展示了DefaultJSONParser.getDateFormat方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test_dateFormat
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
public void test_dateFormat() throws Exception {
DefaultJSONParser parser = new DefaultJSONParser("{}");
parser.setDateFormat("yyyy-DD-mm");
SimpleDateFormat format = new SimpleDateFormat("yyyy-DD-mm", JSON.defaultLocale);
format.setTimeZone(JSON.defaultTimeZone);
parser.setDateFomrat(format);
parser.getDateFomartPattern();
parser.getDateFormat();
parser.parse();
parser.close();
}
示例2: cast
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
protected <T> T cast(DefaultJSONParser parser, Type clazz, Object fieldName, Object val) {
if (val == null) {
return null;
}
if (val instanceof java.util.Date) {
return (T) new java.sql.Timestamp(((Date) val).getTime());
}
if (val instanceof Number) {
return (T) new java.sql.Timestamp(((Number) val).longValue());
}
if (val instanceof String) {
String strVal = (String) val;
if (strVal.length() == 0) {
return null;
}
DateFormat dateFormat = parser.getDateFormat();
try {
Date date = (Date) dateFormat.parse(strVal);
return (T) new Timestamp(date.getTime());
} catch (ParseException e) {
// skip
}
long longVal = Long.parseLong(strVal);
return (T) new java.sql.Timestamp(longVal);
}
throw new JSONException("parse error");
}
示例3: cast
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
protected <T> T cast(DefaultJSONParser parser, Type clazz, Object fieldName, Object val) {
if (timestamp) {
return castTimestamp(parser, clazz, fieldName, val);
}
if (val == null) {
return null;
}
if (val instanceof java.util.Date) {
val = new java.sql.Date(((Date) val).getTime());
} else if (val instanceof Number) {
val = (T) new java.sql.Date(((Number) val).longValue());
} else if (val instanceof String) {
String strVal = (String) val;
if (strVal.length() == 0) {
return null;
}
long longVal;
JSONScanner dateLexer = new JSONScanner(strVal);
try {
if (dateLexer.scanISO8601DateIfMatch()) {
longVal = dateLexer.getCalendar().getTimeInMillis();
} else {
DateFormat dateFormat = parser.getDateFormat();
try {
java.util.Date date = (java.util.Date) dateFormat.parse(strVal);
java.sql.Date sqlDate = new java.sql.Date(date.getTime());
return (T) sqlDate;
} catch (ParseException e) {
// skip
}
longVal = Long.parseLong(strVal);
}
} finally {
dateLexer.close();
}
return (T) new java.sql.Date(longVal);
} else {
throw new JSONException("parse error : " + val);
}
return (T) val;
}
示例4: castTimestamp
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
protected <T> T castTimestamp(DefaultJSONParser parser, Type clazz, Object fieldName, Object val) {
if (val == null) {
return null;
}
if (val instanceof java.util.Date) {
return (T) new java.sql.Timestamp(((Date) val).getTime());
}
if (val instanceof Number) {
return (T) new java.sql.Timestamp(((Number) val).longValue());
}
if (val instanceof String) {
String strVal = (String) val;
if (strVal.length() == 0) {
return null;
}
long longVal;
JSONScanner dateLexer = new JSONScanner(strVal);
try {
if (dateLexer.scanISO8601DateIfMatch()) {
longVal = dateLexer.getCalendar().getTimeInMillis();
} else {
DateFormat dateFormat = parser.getDateFormat();
try {
java.util.Date date = (java.util.Date) dateFormat.parse(strVal);
java.sql.Timestamp sqlDate = new java.sql.Timestamp(date.getTime());
return (T) sqlDate;
} catch (ParseException e) {
// skip
}
longVal = Long.parseLong(strVal);
}
} finally {
dateLexer.close();
}
return (T) new java.sql.Timestamp(longVal);
}
throw new JSONException("parse error");
}
示例5: cast
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
protected <T> T cast(DefaultJSONParser parser, Type clazz, Object fieldName, Object val) {
if (val == null) {
return null;
}
if (val instanceof java.util.Date) {
val = new java.sql.Date(((Date) val).getTime());
} else if (val instanceof Number) {
val = (T) new java.sql.Date(((Number) val).longValue());
} else if (val instanceof String) {
String strVal = (String) val;
if (strVal.length() == 0) {
return null;
}
long longVal;
JSONScanner dateLexer = new JSONScanner(strVal);
try {
if (dateLexer.scanISO8601DateIfMatch()) {
longVal = dateLexer.getCalendar().getTimeInMillis();
} else {
DateFormat dateFormat = parser.getDateFormat();
try {
java.util.Date date = (java.util.Date) dateFormat.parse(strVal);
java.sql.Date sqlDate = new java.sql.Date(date.getTime());
return (T) sqlDate;
} catch (ParseException e) {
// skip
}
longVal = Long.parseLong(strVal);
}
} finally {
dateLexer.close();
}
return (T) new java.sql.Date(longVal);
} else {
throw new JSONException("parse error : " + val);
}
return (T) val;
}
示例6: cast
import com.alibaba.fastjson.parser.DefaultJSONParser; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
protected <T> T cast(DefaultJSONParser parser, Type clazz, Object fieldName, Object val) {
if (val == null) {
return null;
}
if (val instanceof java.util.Date) {
return (T) val;
} else if (val instanceof Number) {
return (T) new java.util.Date(((Number) val).longValue());
} else if (val instanceof String) {
String strVal = (String) val;
if (strVal.length() == 0) {
return null;
}
JSONScanner dateLexer = new JSONScanner(strVal);
try {
if (dateLexer.scanISO8601DateIfMatch(false)) {
Calendar calendar = dateLexer.getCalendar();
if (clazz == Calendar.class) {
return (T) calendar;
}
return (T) calendar.getTime();
}
} finally {
dateLexer.close();
}
DateFormat dateFormat = parser.getDateFormat();
try {
return (T) dateFormat.parse(strVal);
} catch (ParseException e) {
// skip
}
long longVal = Long.parseLong(strVal);
return (T) new java.util.Date(longVal);
}
throw new JSONException("parse error");
}