ashish vyas :
DateFormat utcFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
utcFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
DateFormat indianFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
indianFormat .setTimeZone(TimeZone.getTimeZone("Asia/Kolkata"));
String output = null;
try {
Date timestamp = null;
timestamp = utcFormat.parse(createdAt);
output = indianFormat.format(timestamp);
} catch (ParseException e) {
Log.d("ParseError", String.valueOf(e));
}
I want to convert GMT time of format "2020-03-16T18:50:39.656Z
" to IST time of same format as GMT but I am getting unparseable exception
Dawood says reinstate Monica :
The Z
at the end of your createdAt
value is an ISO 8601 time zone symbol. To parse it, you need to have X
in your date format string, not Z
. Change your date format string to "yyyy-MM-dd'T'HH:mm:ss.SSSX"
and your program will work.
Alternatively, you could keep Z
in the date format string, but give your input as "2020-03-16T18:50:39.656+0000"
- that is, use the four digit number to represent the time offset in the input, instead of Z
.
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=296090&siteId=1