Convert LocalDateTime to LocalDateTime in UTC

后端 未结 10 1010
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-30 08:20

Convert LocalDateTime to LocalDateTime in UTC.

LocalDateTime convertToUtc(LocalDateTime date) {

    //do conversion

}

I searched over net. Bu

10条回答
  •  时光说笑
    2021-01-30 08:38

    you can implement a helper doing something like that :

    public static LocalDateTime convertUTCFRtoUTCZ(LocalDateTime dateTime) {
        ZoneId fr = ZoneId.of("Europe/Paris");
        ZoneId utcZ = ZoneId.of("Z");
        ZonedDateTime frZonedTime = ZonedDateTime.of(dateTime, fr);
        ZonedDateTime utcZonedTime = frZonedTime.withZoneSameInstant(utcZ);
        return utcZonedTime.toLocalDateTime();
    }
    

提交回复
热议问题