Reputation: 1992
I am trying to parse following date in android to device local time. The date is Thu Apr 07 18:26:42 GMT+05:30 2016 . I want to get this date in any other format, say MM-dd-yyyy.
Here is what I have tried :
SimpleDateFormat inputFormat = new SimpleDateFormat(
"EEE MMM dd HH:mm:ss 'GMT' Z yyyy", Locale.US);
inputFormat.setTimeZone(TimeZone.getTimeZone("Etc/UTC"));
SimpleDateFormat outputFormat = new SimpleDateFormat("MMM dd, yyyy h:mm a");
Date date = inputFormat.parse("Thu Apr 07 18:26:42 GMT+05:30 2016");
String outputText = outputFormat.format(date);
WriteLog.Print("outputText" + outputText);
Please tell me what I am doing wrong here. The above code is giving me exception saying unparseable date.
Thanks
Upvotes: 1
Views: 445
Reputation: 16038
The issue in your case is that you have a bit of whitespace in your inputFormat
.
SimpleDateFormat inputFormat = new SimpleDateFormat(
"EEE MMM dd HH:mm:ss 'GMT' Z yyyy", Locale.US);
Instead you need to have:
SimpleDateFormat inputFormat = new SimpleDateFormat(
"EEE MMM dd HH:mm:ss 'GMT'Z yyyy", Locale.US);
Upvotes: 1