Created
December 10, 2018 18:52
-
-
Save IT-Berater/9dc098b1f5f1e0aececc2036ca453bfb to your computer and use it in GitHub Desktop.
Zeitumrechnung - UTC String to ZonedDateTime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package de.wenzlaff.model; | |
import java.time.LocalDateTime; | |
import java.time.ZoneId; | |
import java.time.ZonedDateTime; | |
import java.time.format.DateTimeFormatter; | |
/** | |
* Zeitumrechnung | |
* @author Thomas Wenzlaff | |
* | |
*/ | |
public class Zeit { | |
/** | |
* Liefer die Zeitzone mit Datum und Uhrzeit aus einem UTC String. Umgerechnet | |
* auf Europa (+1 Stunde). | |
* | |
* Die Koordinierte Weltzeit (UTC) ist keine Zeitzone, sondern ein Zeitstandard | |
* für die Berechnung von Ortszeiten in Zeitzonen weltweit. Veraltet: (aber | |
* gleiche wie UTC) Greenwich Mean Time (GMT) ist eine Zeitzone. Sie orientiert | |
* sich an der UTC und wird heute in mehreren Ländern noch offiziell verwendet, | |
* darunter Großbritannien. | |
* | |
* @param eingagsZeitpunktUTC in der Form yyyy-MM-dd HH:mm:ss UTC z.B. | |
* 2018-12-10 12:00:00 UTC | |
* @return die ZonedDateTime auf Europa umgerechnet (+1 Stunde) z.B. 2018-12-10 | |
* 13:00:00 Europa/Berlin | |
*/ | |
public static ZonedDateTime getZonedDateTimeFromUTC(String eingagsZeitpunktUTC) { | |
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss 'UTC'"); | |
LocalDateTime dateTimeUTC = LocalDateTime.parse(eingagsZeitpunktUTC, formatter); | |
ZonedDateTime inputUTC = ZonedDateTime.of(dateTimeUTC, ZoneId.of("UTC")); | |
ZonedDateTime lokalEuropa = inputUTC.withZoneSameInstant(ZoneId.of("Europe/Berlin")); // UTC in Europa Zeitzone | |
// konvertieren | |
return lokalEuropa; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment