Last active
October 12, 2018 17:14
-
-
Save hoangtranwork/ae4e7b264dbc3db6608ecb81c2f37642 to your computer and use it in GitHub Desktop.
Java/Kotlin DateTimeFormatter to parse Apple version of RFC3339 date returned by Apple API (Itune receipt)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val appleRfc3339DateFormatter: DateTimeFormatter = | |
DateTimeFormatterBuilder() | |
.appendValue(YEAR, 4).appendLiteral('-').appendValue(MONTH_OF_YEAR, 2).appendLiteral('-').appendValue(DAY_OF_MONTH, 2) | |
.appendLiteral(' ') | |
.appendValue(HOUR_OF_DAY, 2).appendLiteral(':').appendValue(MINUTE_OF_HOUR, 2).appendLiteral(':').appendValue(SECOND_OF_MINUTE, 2) | |
.appendLiteral(' ') | |
.appendZoneId() | |
.toFormatter() | |
val aRfc3339DateString = "2016-03-17 03:24:38 Etc/GMT" | |
val parsedDate = ZonedDateTime.parse(aRfc3339DateString, appleRfc3339DateFormatter).toDate() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
RFC3339 is so loose that it's better to make specialized parser for each vendor. In this case, Apple decides that their date should use
space
instead ofT
to separate the date and time part and no fraction seconds.