java.time.YearMonth.atDay() 方法示例



說明

java.time.YearMonth.atDay(int dayOfMonth) 方法將此年月與月中的某天組合起來以建立 LocalDate。

宣告

以下是 java.time.YearMonth.atDay(int dayOfMonth) 方法的宣告。

public LocalDate atDay(int dayOfMonth)

public static LocalDate atDay(int dayOfMonth)

引數

dayOfMonth − 要使用的月份的天數,範圍為 1 至 31。

返回值

由此年份和指定的月份日期形成的本地日期,非空。

異常

DateTimeException − 如果該天對於年月無效。

示例

package com.tutorialspoint;

import java.time.LocalDate;
import java.time.YearMonth;

public class YearMonthDemo {
   public static void main(String[] args) {

      YearMonth year = YearMonth.of(2015,12);
      
      LocalDate date = year.atDay(26);
      System.out.println(date);  
   }
}

即時演示

2015-12-26
列印頁面
廣告
© . All rights reserved.