I have used following code to convert UTC time to device current time zone time. It works fine on Indian Standard Time (IST). But it adds 1 hour additionally when device time zone is Sydney, Australia.
For example, I give UTC time like 2016-10-10T09:10:00 and it is converts as 8:10 PM, but actually I need 7:10 PM.What is the problem in my code?
public static String convertToLocalTimeFormat(String utcDateTimeString) {
SimpleDateFormat simpleDateFormat;
String formattedDateString = "";
simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.getDefault());
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
Date parsedDateObject;
try {
parsedDateObject = simpleDateFormat.parse(utcDateTimeString);
SimpleDateFormat expectedSimpleDateFormat = new SimpleDateFormat("hh:mm a", Locale.getDefault());
formattedDateString = expectedSimpleDateFormat.format(parsedDateObject);
} catch (ParseException e) {
e.printStackTrace();
return formattedDateString;
}
return formattedDateString;
}