java.time.YearMonth.<init>()方法的使用及代码示例

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

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

YearMonth.<init>介绍

[英]Constructor.
[中]建造师。

代码示例

代码示例来源:origin: com.github.seratch/java-time-backport

  1. /**
  2. * Returns a copy of this year-month with the new year and month, checking
  3. * to see if a new object is in fact required.
  4. *
  5. * @param newYear the year to represent, validated from MIN_YEAR to MAX_YEAR
  6. * @param newMonth the month-of-year to represent, validated not null
  7. * @return the year-month, not null
  8. */
  9. private YearMonth with(int newYear, int newMonth) {
  10. if (year == newYear && month == newMonth) {
  11. return this;
  12. }
  13. return new YearMonth(newYear, newMonth);
  14. }

代码示例来源:origin: stackoverflow.com

  1. // TODO: Which time zone are you interested in?
  2. YearMonth yearMonth = new YearMonth();
  3. DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyyMM");
  4. List<String> dates = new ArrayList<>();
  5. for (int i = 0; i < 6; i++) {
  6. dates.add(formatter.print(yearMonth.plusMonths(i)));
  7. }

代码示例来源:origin: stackoverflow.com

  1. YearMonth date = new YearMonth("2014-01");
  2. date = date.minusMonths(1); //will equal 2013-11

代码示例来源:origin: com.github.seratch/java-time-backport

  1. /**
  2. * Obtains an instance of {@code YearMonth} from a year and month.
  3. *
  4. * @param year the year to represent, from MIN_YEAR to MAX_YEAR
  5. * @param month the month-of-year to represent, from 1 (January) to 12 (December)
  6. * @return the year-month, not null
  7. * @throws DateTimeException if either field value is invalid
  8. */
  9. public static YearMonth of(int year, int month) {
  10. YEAR.checkValidValue(year);
  11. MONTH_OF_YEAR.checkValidValue(month);
  12. return new YearMonth(year, month);
  13. }

代码示例来源:origin: stackoverflow.com

  1. String input = "2014-02";
  2. YearMonth yearMonth = YearMonth.parse( input ); // Construct by parsing string.
  3. int year = yearMonth.getYear();
  4. int month = yearMonth.getMonthOfYear();
  5. String output = yearMonth.toString(); // Joda-Time uses ISO 8601 formats by default for generating strings.
  6. YearMonth yearMonth2 = new YearMonth( year , month ); // Construct by passing numbers for year and month.

相关文章