Created
April 3, 2019 08:04
-
-
Save tasdemirbahadir/c9ed99cdd262b91692e269d419758130 to your computer and use it in GitHub Desktop.
Convert java.util.Date time zone between UTC and Turkish time zones.
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
private static final ZoneId TURKEY_ZONE_ID = ZoneId.of("Turkey"); | |
private static final ZoneId UTC_ZONE_ID = ZoneId.of("UTC"); | |
public static Date convertTurkeyToUTC(Date date) { | |
return Date.from(date.toInstant().atZone(UTC_ZONE_ID).toLocalDateTime().atZone(TURKEY_ZONE_ID).toInstant()); | |
} | |
public static Date convertUTCToTurkey(Date date) { | |
return Date.from(date.toInstant().atZone(TURKEY_ZONE_ID).toLocalDateTime().atZone(UTC_ZONE_ID).toInstant()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It seems a little bit complex but works like a charm when needed to convert java.util.Date time zone value between UTC and Turkish time zones. I know it is not a best practice to use java.util.Date but you need it with hibernate and when writing unit/integration tests.