I would like to Wed, 21 Oct 2016 07:28:00 GMT date, like Wed, 21 Oct 2016 07:28:00 GMT with DateTimeFormatter , in Instant . To create the template, I used the official documentation: DateTimeFormatter
My code is:
String date = "Wed, 21 Oct 2016 07:28:00 GMT"; DateTimeFormatter gmtFormat = DateTimeFormatter.ofPattern("EEE' dd LLL yyyy HH:mm:ss '''"); TemporalAccessor parsed = gmtFormat.parse(date); Instant a = Instant.from(parsed); System.out.println(a);
But every time I get this error:
Exception in thread "main" java.time.format.DateTimeParseException: Text 'Wed, 21 Oct 2016 07:28:00 GMT' could not be parsed at index 0 at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949) at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1777)
At index 0 there is Wed , I used EEE , which represents day-of-week by definition, there are also examples that represent: Tue; Tuesday; T Tue; Tuesday; T Tue; Tuesday; T
I also tried using bottom and top, but not successfully. What's wrong? Did I miss something?
source share