java.time.LocalDateTime.getDayOfYear() 方法示例



說明

java.time.LocalDateTime.getDayOfYear() 方法獲取年中第幾天。

宣告

以下是 java.time.LocalDateTime.getDayOfYear() 方法的宣告。

public int getDayOfYear()

返回值

年中第幾天,從 1 到 365,或者閏年的 366。

示例

以下示例演示瞭如何使用 java.time.LocalDateTime.getDayOfYear() 方法。

package com.tutorialspoint;

import java.time.LocalDateTime;

public class LocalDateTimeDemo {
   public static void main(String[] args) {
 
      LocalDateTime date = LocalDateTime.parse("2017-02-03T12:30:30");
      System.out.println(date.getDayOfYear());  
   }
}

讓我們編譯並執行以上程式,這將產生以下結果 −

34
廣告
© . All rights reserved.