Gson日期格式异常-com.google.gson.JsonSyntaxException

Gson使用中遇到的Timestamp格式问题

Gson gson = new GsonBuilder()
            .registerTypeAdapter(Timestamp.class,new TimestampTypeAdapter())
            .setDateFormat("yyyy-MM-dd HH:mm:ss")
            .create();
String newValue = gson.toJson(System.currentTimeMillis());

Gson使用中遇到的Date格式问题

Gson gson = new GsonBuilder()
            .setDateFormat("yyyy-MM-dd HH:mm:ss")
            .create(); 
String newValue = gson.toJson(new Date(System.currentTimeMillis()),Date.class); 

猜你喜欢

转载自blog.csdn.net/u012869196/article/details/80843180