“宽容"有什么用? [英] What is the use of "lenient "?

查看:46
本文介绍了“宽容"有什么用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里 lenient 用于 Java DateFormat.我查看了文档,但没有明白它在说什么.

Here lenient is used in Java DateFormat. I checked the doc, but didn't get what it was saying.

谁能告诉我这个 lenient 的用途是什么,并提供一个我们使用它的实时示例?

Can any body please tell me what is the use of this lenient, with one real time example where we use it?

推荐答案

javadoc 明确指出:

指定日期/时间解析是否宽松.和宽松的解析,解析器可以使用启发式来解释输入不完全匹配此对象的格式.通过严格的解析,输入必须与此对象的格式匹配.

Specify whether or not date/time parsing is to be lenient. With lenient parsing, the parser may use heuristics to interpret inputs that do not precisely match this object's format. With strict parsing, inputs must match this object's format.

因此,如果您有一个模式并创建一个严格匹配您的模式的日期对象,请将 lenient 设置为 false.此外,默认情况下 DateFormat 是宽松的.

So, if you have a pattern and create a date object that strictly matches your pattern, set lenient to false. Also, DateFormat is lenient, by default.

基本上,DateFormat 设置 Calendar.setLenient 和 Javadoc 声明:

Basically, DateFormat sets Calendar.setLenient and the Javadoc states:

指定日期/时间解释是否宽松.有了宽松的解释,诸如1996 年 2 月 942 日"之类的日期将被视为等同于 2 月 1 日之后的第 941 天,1996. 严格(非宽松)解释,这样的日期会导致要抛出的异常.默认为宽松.

Specifies whether or not date/time interpretation is to be lenient. With lenient interpretation, a date such as "February 942, 1996" will be treated as being equivalent to the 941st day after February 1, 1996. With strict (non-lenient) interpretation, such dates will cause an exception to be thrown. The default is lenient.

这篇关于“宽容"有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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