convert String to Date in android
anyone know how to convert the following string to Date?
"Fri Jul 30 16:19:36 GMT+02.00 2021"
i tried:
SimpleDateFormat formatter = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzzz yyyy");
try {String temp = value2[i].trim();
expiry = formatter.parse(temp);
} catch (Exception e) {
e.printStackTrace();
}
but,it doesn't wo开发者_如何学编程rk.
z
expects the format GMT+02:00
not GMT+02.00
replace the .
and it should work.
Worked for me with the following code:
SimpleDateFormat formatter = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzzz yyyy");
try {
String temp = "Fri Jul 30 16:19:36 GMT+02:00 2021";
Date expiry = formatter.parse(temp);
} catch (Exception e) {
e.printStackTrace();
}
Date cDate = new Date(String);
String fDate = new SimpleDateFormat("yyyy-MM-dd").format(cDate);
精彩评论