Gson时间格式报错

Caused by: java.text.ParseException: Unparseable date: "1492134656258" (at offset 13)
原因是Gson对Date时间格式处理,时间格式超长
处理方法:
private static Gson dateGson = new GsonBuilder()
.setDateFormat("yyyy-MM-dd HH:mm:ss")
.registerTypeAdapter(Date.class, new JsonDeserializer() {
@Override
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
return new Date(json.getAsJsonPrimitive().getAsLong());
}
}).create();

你可能感兴趣的:(android常用功能)