DateTimeFormatter.parseLocalDate引发UnsupportedOperationException [英] DateTimeFormatter.parseLocalDate throws UnsupportedOperationException

查看:62
本文介绍了DateTimeFormatter.parseLocalDate引发UnsupportedOperationException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用于 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆