I have to convert 2017-10-12T09:48:28.338Z
to IST ie dd-MM-yyyy HH:mm:ss
. The code i used throws java.lang.IllegalArgumentException: Unknown pattern character 'Y'
Here is my code :
private String getStandardTime(String dateStr) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dddd'T'HH:mm:ss.SSSZ");
df.setTimeZone(TimeZone.getTimeZone("UTC"));
Date date = null;
try {
date = df.parse(dateStr);
} catch (ParseException e) {
e.printStackTrace();
}
df.setTimeZone(TimeZone.getDefault());
String formattedDate = df.format(date);
return formattedDate;
}
Can anyone help me out here ? What i am doing wrong . for reference i checked
http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html#number
Try using the below line in your code:
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
Z represent Timezone character, you have to quote it like 'Z'. Also you are using dddd instead of dd.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.