scarpacci
scarpacci

Reputation: 9194

Parse UTC date using java.time

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)


    }
}

Upvotes: 1

Views: 565

Answers (1)

Ervi B
Ervi B

Reputation: 800

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

Upvotes: 1

Related Questions