账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    Springboot Linux 时区 时间差 问题
    • 2020-01-01 00:00
    • 10
    60
    0
    • 服务器系统是centos 7,我的项目是springboot 2.x
    • springboot 内已经在配置文件设置
    spring:
      jackson:
        date-format: yyyy-MM-dd HH:mm:ss
        time-zone: Asia/Shanghai
    • 从项目的 controller 返回 Date 类型时候日期时间是对的,代码如下:
        @GetMapping("/getJavaDate")
        public Date getJavaDate(){
            return new Date();
        }
    • controller 内通过 new Date()之后格式化为 yyyy-MM-dd HH:mm:ss 后返回 String 类型,就少了8小时,代码如下:
        @GetMapping("/getFormatDate")
        public String getFormatDate() throws Exception {
            return DatetimeUtil.formatDate(new Date());
        }
    • 要如何解决这个问题,难道要我手动给 new 出来的时间+8 ?
    1
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 10 元积分
        全部回答
    • 0
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部