org.threeten.bp.YearMonth.withYear()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(1.5k)|赞(0)|评价(0)|浏览(115)

本文整理了Java中org.threeten.bp.YearMonth.withYear()方法的一些代码示例,展示了YearMonth.withYear()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YearMonth.withYear()方法的具体详情如下:
包路径:org.threeten.bp.YearMonth
类名称:YearMonth
方法名:withYear

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));

相关文章