一般从数据库中直接查找出来的日期格式是是一段数字,如何转换成我们需要的呢:

方法一:

使用date工具对象

/**
     * 日期转String  yyyy-MM-dd HH:mm:ss.SSS格式
     */
    public static String dateToString(Date date){
        if(date == null){
            return "";
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(date);
    }

方法二:

在对象的日期属性的get方法上添加转换格式的代码

@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")

相关文章:

  • 2021-12-22
  • 2022-12-23
  • 2022-02-19
  • 2022-02-07
  • 2021-12-12
  • 2022-12-23
  • 2021-08-09
猜你喜欢
  • 2022-01-07
  • 2021-11-06
  • 2022-12-23
  • 2021-12-07
  • 2022-03-01
  • 2022-12-23
  • 2022-03-04
相关资源
相似解决方案