问题描述
用于 parseLocalDate 表示将抛出UnsupportedOperationException
如果不支持解析". 如果不支持解析"是什么意思?我正在查看源代码,找不到在任何地方抛出UnsupportedOperationException
的地方.有没有人遇到过调用parseLocalDate
引发此异常的情况?
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 有两种用法:
- 打印日期;
- 解析日期;
创建,您将其传递给DateTimePrinter 和 DateTimeParser .
When you create DateTimeFormatter instance, you pass to it DateTimePrinter and DateTimeParser.
如果格式化程序仅具有打印机,并且您希望 parse 日期-将抛出UnsupportedOperationException
.
If your formatter has only printer, and you want parse date - UnsupportedOperationException
will be thrown.
如果格式化程序只有解析器,并且您希望打印日期-将抛出UnsupportedOperationException
.
If your formatter has only parser, and you want print date - UnsupportedOperationException
will be thrown.
示例
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
这篇关于DateTimeFormatter.parseLocalDate引发UnsupportedOperationException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!