1

I am having an issue trying to parse a date using java.time.LocalDateTime.parse. I am sure that it is something silly that I am completely overlooking, but cannot for the life of me figure it out. If the date string does not have a "Z" at the end it works fine, but if it does it will fail during the parse.

Was referencing: DateTimeFormatter

ISO_INSTANT

Code:

import java.time.Instant
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.format.DateTimeFormatter



class GroovyPrintExample {
    static void main(String[] args) {


        def formatter = DateTimeFormatter.ISO_INSTANT
        def test = "2015-11-12T14:11:03.354Z"
        def dateTime = LocalDateTime.parse(test, formatter)


    }
}
tim_yates
  • 167,322
  • 27
  • 342
  • 338
scarpacci
  • 8,957
  • 16
  • 79
  • 144

1 Answers1

1

The Z is for timezone, right? Have you tried using ZonedDateTime instead?

Ervi B
  • 770
  • 7
  • 16
  • Hi Ervi, I will try that. I thought for sure I had, but will do so again. Saw this linked that seems strange http://stackoverflow.com/questions/25612129/java-8-datetimeformatter-and-iso-instant-issues-with-zoneddatetime?lq=1 – scarpacci Apr 08 '16 at 05:32
  • That was it. Doh....thought for sure I had tried that. Must have used it elsewhere. Thanks for the tip. – scarpacci Apr 08 '16 at 14:48
  • Glad to help, @scarpacci! – Ervi B Apr 08 '16 at 18:09