master_er 2018-08-22 03:36 采纳率: 66.7%
浏览 2074
已结题

gson转换字符型的日期 date问题

前端传的"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"

  • 写回答

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();
    }

    评论

报告相同问题?

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容