Created
September 23, 2020 13:20
-
-
Save aslamanver/77c617fbf3e9789456cedbb2cf3acbcf to your computer and use it in GitHub Desktop.
Java convert date from UTC timezone
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 { | |
String inputTime = "2020-06-19T04:18:37.636Z"; | |
SimpleDateFormat inputDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); | |
inputDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); | |
Date date = inputDateFormat.parse(inputTime); | |
SimpleDateFormat outputDateFormat = new SimpleDateFormat("HH:mm:ss"); | |
outputDateFormat.setTimeZone(TimeZone.getTimeZone("Asia/Colombo")); | |
String outputTime = outputDateFormat.format(date); | |
System.out.println(outputTime); | |
} catch (Exception ex) { | |
ex.printStackTrace(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment