本文整理了Java中org.threeten.bp.YearMonth.withYear()
方法的一些代码示例,展示了YearMonth.withYear()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YearMonth.withYear()
方法的具体详情如下:
包路径:org.threeten.bp.YearMonth
类名称:YearMonth
方法名:withYear
[英]Returns a copy of this YearMonth with the year altered.
This instance is immutable and unaffected by this method call.
[中]返回已更改年份的本年月份的副本。
此实例是不可变的,不受此方法调用的影响。
代码示例来源:origin: stackoverflow.com
public static void main(String[] args) {
System.out.println(mapToCurrentCentury(16, 11));
System.out.println(mapToCurrentCentury(116, 11));
System.out.println(mapToCurrentCentury(1116, 11));
}
private static YearMonth mapToCurrentCentury(int year, int month) {
if(year < 1000) {
YearMonth now = YearMonth.now();
return now.withYear(((now.get(ChronoField.YEAR) / 1000) * 1000) + (year % 1000)).withMonth(month);
}
else {
return YearMonth.of(year, month);
}
}
代码示例来源:origin: ThreeTen/threetenbp
case MONTH_OF_YEAR: return withMonth((int) newValue);
case PROLEPTIC_MONTH: return plusMonths(newValue - getLong(PROLEPTIC_MONTH));
case YEAR_OF_ERA: return withYear((int) (year < 1 ? 1 - newValue : newValue));
case YEAR: return withYear((int) newValue);
case ERA: return (getLong(ERA) == newValue ? this : withYear(1 - year));
代码示例来源:origin: org.threeten/threetenbp
case MONTH_OF_YEAR: return withMonth((int) newValue);
case PROLEPTIC_MONTH: return plusMonths(newValue - getLong(PROLEPTIC_MONTH));
case YEAR_OF_ERA: return withYear((int) (year < 1 ? 1 - newValue : newValue));
case YEAR: return withYear((int) newValue);
case ERA: return (getLong(ERA) == newValue ? this : withYear(1 - year));
内容来源于网络,如有侵权,请联系作者删除!