Last active
January 28, 2018 08:30
-
-
Save nhancv/c59be969378ed5d8d45496b949246bee to your computer and use it in GitHub Desktop.
Convert TimeZone [From UTC to LocalTime with DST mode default]
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
try { | |
//Time formatter input | |
String dataTime = "2018-07-18 11:59:59"; | |
String dateTimePattern = "yyyy-MM-dd HH:mm:ss"; | |
ZoneId zoneUTC = ZoneId.of("Z"); | |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(dateTimePattern).withZone(zoneUTC); | |
ZonedDateTime zonedDateTime = ZonedDateTime.parse(dataTime, dateTimeFormatter); | |
//Convert UTC Time to Local time | |
zonedDateTime = zonedDateTime.toOffsetDateTime().atZoneSameInstant(ZoneId.systemDefault()); | |
System.out.println(zonedDateTime); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment