Skip to content

Instantly share code, notes, and snippets.

@aslamanver
Created September 23, 2020 13:20
Show Gist options
  • Save aslamanver/77c617fbf3e9789456cedbb2cf3acbcf to your computer and use it in GitHub Desktop.
Save aslamanver/77c617fbf3e9789456cedbb2cf3acbcf to your computer and use it in GitHub Desktop.
Java convert date from UTC timezone
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