0

Is there any standard way of parsing RFC3339 compliant dateTime instead of using patterns in java ?

It seems there isn't one. I tried finding solution over the internet but most of them were using patterns for parsing RFC3339 compliant dateTime values.

5
  • Java doesn't even support ISO 8601 fully. What format are your dates actually coming in (irrespective of standard number)? Commented Apr 30, 2024 at 10:45
  • 1
    If you’re talking about this format, OffsetDateTime’s parse and toString methods already do this. No DateTimeFormatter is needed. Commented Apr 30, 2024 at 12:51
  • 1
    In what formatting pattern are you interested? Commented May 1, 2024 at 0:56
  • What is the problem with using patterns? Commented May 1, 2024 at 3:15
  • All of the examples in section 5.8 of RFC 3339 can be parsed with DateTimeFormatter.ISO_OFFSET_DATE_TIME. Which are the RFC 3339 date-time strings that you want to parse and cannot parse with that formatter? Commented May 23, 2024 at 13:31

1 Answer 1

1

RFC 3339 by The Internet Society is a self-described “profile” of the ISO 8601. But ISO does not provide for profiles. And the RFC makes some screwy unwise contradictions of ISO 8601.

So, I suggest you forget about the RFC. Focus instead on ISO 8601, nicely documented on Wikipedia.

The java.time classes use ISO 8601 formats by default when parsing/generating text. No need for you to define a formatting pattern.

You neglected to mention the specific format of interest. Several are predefined as constants on the DateTimeFormatter class.

Perhaps you meant the format for a date with time as seen with an offset from UTC of zero hours-minutes-seconds. For that, use Instant class. The Z on the end is an abbreviation for an offset of zero, +00:00.

Instant instant = Instant.parse( "2007-12-03T10:15:30.1764435Z" ) ;
String output = instant.toString() ;  // Produces: 2007-12-03T10:15:30.1764435Z

Those methods are using the constant DateTimeFormatter.ISO_INSTANT formatter object.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.