I have this date:
"Wed Dec 31 00:00:00 GMT-8 1969"
But it cannot be parsed with this SimpleDateFormat:
new SimpleDateFormat("EEE MMM dd hh:mm:ss zzz yyyy");
How do I specify the -8 in the format string? I have tried Z and X after reading the SDF docs, but to no avail. What should I use?
If you are using java 8, you can try DateTimeFormatter with a pattern of "EEE MMM d HH:mm:ss O yyyy" likes:
String date = "Wed Dec 31 00:00:00 GMT-8 1969";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEE MMM d HH:mm:ss O yyyy");
LocalDateTime dateTime = LocalDateTime.parse(date, formatter);
O represent localized zone-offset and can format zone offset like GMT+8, GMT+08:00, UTC-08:00. You can see Offset O in DateTimeFormatter for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With