Javascript Date() give wrong date off by one hour

后端 未结 4 820
迷失自我
迷失自我 2020-12-03 21:33

I send this date from my controller in java (Spring-MVC) the type in mysql is datetime

@Temporal(TemporalType.TIMESTAM         


        
4条回答
  •  粉色の甜心
    2020-12-03 22:02

    To be more specific

     time = new Date("2018-06-01 " + time);
                var offset = time.getTimezoneOffset();
                offset = Math.abs(offset / 60);
                time.setHours(time.getHours() + offset);
    

    in this case time is equal to hours with leading zeros:minutes with leading zeros. This will add the hours difference to the UTC. If you pass a string to date it is treated as UTC.

提交回复
热议问题