“宽松”的用法是什么? [英] What is the use of "lenient "?

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

问题描述

这里 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.

所以,如果你有一个模式并创建一个日期对象严格匹配您的模式,将宽松设置为 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月9日的日期将为
,被视为相当于1996年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天全站免登陆