Java中的OffsetDateTime類的getDayOfYear()方法獲取day-of-year字段。
用法:
public int getDayOfYear()
參數:此方法接受不接受任何參數。
返回值:它返回day-of-the-year,範圍是1到365,如果是a年則是366。
以下示例程序旨在說明getDayOfMonth()方法:
示例1:
// Java program to demonstrate the getDayOfYear() method
import java.time.OffsetDateTime;
public class GFG {
public static void main(String[] args)
{
// parses a date
OffsetDateTime date = OffsetDateTime.parse("2018-12-03T12:30:30+01:00");
// Prints the day of given date in year
System.out.println("Day in year: " + date.getDayOfYear());
}
}
輸出:
Day in year: 337
程序2:
// Java program to demonstrate the getDayOfYear() method
import java.time.OffsetDateTime;
public class GFG {
public static void main(String[] args)
{
// parses a date
OffsetDateTime date = OffsetDateTime.parse("2016-12-31T12:30:30+01:00");
// Prints the day of given date in year
System.out.println("Day in year: " + date.getDayOfYear());
}
}
輸出:
Day in year: 366
參考: https://docs.oracle.com/javase/8/docs/api/java/time/OffsetDateTime.html#getDayOfYear–
相關用法
- Java ZonedDateTime getDayOfYear()用法及代碼示例
- Java LocalDateTime getDayOfYear()用法及代碼示例
- Java LocalDate getDayOfYear()用法及代碼示例
- Java OffsetDateTime until()用法及代碼示例
- Java OffsetDateTime from()用法及代碼示例
- Java OffsetDateTime with()用法及代碼示例
- Java OffsetDateTime get()用法及代碼示例
- Java OffsetDateTime minusMonths()用法及代碼示例
- Java OffsetDateTime minusDays()用法及代碼示例
- Java OffsetDateTime isAfter()用法及代碼示例
- Java OffsetDateTime getOffset()用法及代碼示例
- Java OffsetDateTime withHour()用法及代碼示例
- Java OffsetDateTime isEqual()用法及代碼示例
- Java OffsetDateTime minusMinutes()用法及代碼示例
- Java OffsetDateTime plusMinutes()用法及代碼示例
注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 OffsetDateTime getDayOfYear() method in Java with examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。