How to parse the “GMT+hours:minutes” or “GMT-hours:minutes” using SimpleDateFormat in Java (Android)
-
02-10-2019 - |
Pergunta
For example, I want to parse the string below:
Tue Sep 28 18:02:24 GMT+08:00 2010
And I use the pattern for the SimpleDateFormat
:
new SimpleDateFormat("EEE MMM dd HH:mm:ss zzzzzzzzz yyyy");
But I keep getting the ParseException
.
How to fix this?
Thanks a lot.
Solução
use one z, as in the examples here
new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
Outras dicas
Alright, I found the solution here.
new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", Locale.ENGLISH);
But what's the difference between using 'z' and 'Z' here? Are they the same?
Even if you have many z's it work.
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow