本文整理了Java中org.threeten.bp.Year.parse()
方法的一些代码示例,展示了Year.parse()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Year.parse()
方法的具体详情如下:
包路径:org.threeten.bp.Year
类名称:Year
方法名:parse
[英]Obtains an instance of Year from a text string such as 2007.
The string must represent a valid year. Years outside the range 0000 to 9999 must be prefixed by the plus or minus symbol.
[中]从文本字符串(如2007)中获取年份的实例。
字符串必须表示有效的年份。0000到9999之间的年份必须以加号或减号作为前缀。
代码示例来源:origin: ThreeTen/threetenbp
/**
* Obtains an instance of {@code Year} from a text string such as {@code 2007}.
* <p>
* The string must represent a valid year.
* Years outside the range 0000 to 9999 must be prefixed by the plus or minus symbol.
*
* @param text the text to parse such as "2007", not null
* @return the parsed year, not null
* @throws DateTimeParseException if the text cannot be parsed
*/
public static Year parse(CharSequence text) {
return parse(text, PARSER);
}
代码示例来源:origin: org.threeten/threetenbp
/**
* Obtains an instance of {@code Year} from a text string such as {@code 2007}.
* <p>
* The string must represent a valid year.
* Years outside the range 0000 to 9999 must be prefixed by the plus or minus symbol.
*
* @param text the text to parse such as "2007", not null
* @return the parsed year, not null
* @throws DateTimeParseException if the text cannot be parsed
*/
public static Year parse(CharSequence text) {
return parse(text, PARSER);
}
代码示例来源:origin: com.github.joschi.jackson/jackson-datatype-threetenbp
@Override
protected Year deserialize(String key, DeserializationContext ctxt) throws IOException {
try {
return Year.parse(key, FORMATTER);
} catch (DateTimeException e) {
return _rethrowDateTimeException(ctxt, Year.class, e, key);
}
}
}
代码示例来源:origin: com.github.joschi.jackson/jackson-datatype-threetenbp
@Override
public Year deserialize(JsonParser parser, DeserializationContext context) throws IOException
{
JsonToken t = parser.getCurrentToken();
if (t == JsonToken.VALUE_STRING) {
String string = parser.getValueAsString().trim();
try {
if (_formatter == null) {
return Year.parse(string);
}
return Year.parse(string, _formatter);
} catch (DateTimeException e) {
_rethrowDateTimeException(parser, context, e, string);
}
}
if (t == JsonToken.VALUE_NUMBER_INT) {
return Year.of(parser.getIntValue());
}
if (t == JsonToken.VALUE_EMBEDDED_OBJECT) {
return (Year) parser.getEmbeddedObject();
}
throw context.mappingException("Unexpected token (%s), expected VALUE_STRING or VALUE_NUMBER_INT",
parser.getCurrentToken());
}
}
内容来源于网络,如有侵权,请联系作者删除!