Convert Human Date (Local Time GMT) to date

后端 未结 2 789
生来不讨喜
生来不讨喜 2021-01-29 08:49

I am working on server and server is sending me date on GMT Local Date like Fri Jun 22 09:29:29 NPT 2018 on String format and I convert it into Date like below:

2条回答
  •  孤城傲影
    2021-01-29 09:50

    The Date class is predominantly deprecated, so I would suggest not to use that.

    Perhaps consider using something like the ZonedDateTime class for your problem.

    If you're just looking for 5 hours before the String sent over to you, you could use something like:

    String time = "Fri Jun 22 09:29:29 NPT 2018";
    DateTimeFormatter format = DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss zzz uuuu");
    ZonedDateTime zdt = ZonedDateTime.parse(time, format);
    System.out.println(zdt.minusHours(5));
    

提交回复
热议问题