前端传的"yyyy-MM-dd HH:mm:ss" 格式的字符串 ,后台转换不了:org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: The date should be a string value; nested exception is com.google.gson.JsonParseException: The date should be a string value
后台数据date传到前端 转换成 "yyyy-MM-dd HH:mm:ss" ,但是前端"yyyy-MM-dd HH:mm:ss"传到后端 gson解析不了 。
但是 前端传这种格式就能解析转成date :"2018-08-22T02:44:09.647Z"
gson转换字符型的日期 date问题
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
6条回答 默认 最新
- 丿灬序曲 2018-08-22 03:42关注
应该是你解析的格式没有配好
Date转字符串
Date date = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = formatter.format(date);
System.out.print(dateString);字符串转Date
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date date = null;
String str = "2017-02-18";
try {
date = format.parse(str);
System.out.print(date);
} catch (ParseException e) {
e.printStackTrace();
}解决 无用评论 打赏 举报