The API for parseLocalDate says it will throw UnsupportedOperationException
"if parsing is not supported". What does it mean by 'if parsing is not supported'? I'm looking through the source and can not find anywhere that throws UnsupportedOperationException
. Has anyone ever been in a scenario where this exception was thrown from calling parseLocalDate
?
DateTimeFormatter With Predefined Instances DateTimeFormatter comes with multiple predefined date/time formats that follow ISO and RFC standards. For example, we can use the ISO_LOCAL_DATE instance to parse a date such as ‘2018-03-09': To parse a date with an offset, we can use ISO_OFFSET_DATE to get an output like ‘2018-03-09-03:00':
Since: 2.0 parseLocalDateTime public LocalDateTimeparseLocalDateTime(String text) Parses only the local date-time from the given text, returning a new LocalDate. This will parse the text fully according to the formatter, using the UTC zone. Once parsed, only the local date-time will be used.
DateTimeFormatter With Predefined Instances DateTimeFormatter comes with multiple predefined date/time formats that follow ISO and RFC standards. For example, we can use the ISO_LOCAL_DATE instance to parse a date such as ‘2018-03-09':
Field Detail ISO_LOCAL_DATE public static final DateTimeFormatter ISO_LOCAL_DATE The ISO date formatter that formats or parses a date without an offset, such as '2011-12-03'. This returns an immutable formatter capable of formatting and parsing the ISO-8601 extended local date format.
DateTimeFormatter have two usages:
When you create DateTimeFormatter instance, you pass to it DateTimePrinter and DateTimeParser.
If your formatter has only printer, and you want parse date - UnsupportedOperationException
will be thrown.
If your formatter has only parser, and you want print date - UnsupportedOperationException
will be thrown.
Example
DateTimeFormatter formatter = new DateTimeFormatter(new DateTimePrinter()
{
// implements all abstract methods
}, null); // this instance has printer and hasn't parser
formatter.print(new DateTime()); // works well
formatter.parseDateTime("datetimestring"); // throws exeption
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With