In my android application I have to parse a date of format EEE, dd MMM yyyy HH:mm:ss zzz
. I am extracting the time from this using below method. this works perfect. but the time always displays in GMT format, so I have to convert it in to user time zone, for that I have added one more line in my code before parsing, the code is inputFormatter.setTimeZone(TimeZone.getDefault());
since this is not working I have changed the argument in to TimeZone.getTimeZone("UTC")
, TimeZone.getTimeZone("Asia/Kolkata")
and so on, but nothing works, the time still comes in GMT format.
what is the problem for this actually ? how can I resolve this, any help is appreciated
public static String extractTime(String dateInput) {
Date date = null;
String time;
try {
DateFormat inputFormatter = new SimpleDateFormat(mFormat, Locale.getDefault());
date = inputFormatter.parse(dateInput);
} catch (ParseException e) {
e.printStackTrace();
}
SimpleDateFormat outputFormatter = new SimpleDateFormat("HH:mm:ss");
time = outputFormatter.format(date);
return time;
}
Update
I have tried setting timezone to outputFormatter instead of inputFormatter, but it is still same, no change in output.
Example :
Input : Tue, 21 Jul 2015 09:02:30 GMT
Output getting : 05:02:30