Java LocalDate类| 带示例的getDayOfYear()方法
LocalDate類的getDayOfYear()方法 (LocalDate Class getDayOfYear() method)
getDayOfYear() method is available in java.time package.
getDayOfYear()方法在java.time包中可用。
getDayOfYear() method is used to get the day-of-year field value of this LocalDate object.
getDayOfYear()方法用于獲取此LocalDate對象的年份字段值。
getDayOfYear() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
getDayOfYear()方法是一個非靜態方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。
getDayOfYear() method does not throw an exception at the time of getting the day of the year.
getDayOfYear()方法在獲取一年中的某天時不會引發異常。
Syntax:
句法:
public int getDayOfYear();Parameter(s):
參數:
None
沒有
Return value:
返回值:
The return type of this method is int, it returns the value day-of-year field and the number of days in a year starts from 1 to 365 (i.e. for Non-Leap Year) or from 1 to 366 (i.e. for Leap Year).
此方法的返回類型為int ,它返回值“年的年”字段,并且一年中的天數從1到365(即非-年)或1到366(即Le年)開始)。
Example:
例:
// Java program to demonstrate the example // of getDayOfYear() method // of LocalDateimport java.time.*;public class GetDayOfYearOfLocalDate {public static void main(String args[]) {// Instantiates two LocalDateLocalDate l_da1 = LocalDate.parse("2007-04-05");LocalDate l_da2 = LocalDate.now();// Display l_da1,l_da2System.out.println("LocalDate l_da1 and l_da2: ");System.out.println("l_da1: " + l_da1);System.out.println("l_da2: " + l_da2);System.out.println();// Here, this method gets the value for// the field day-of-year in this// date object l_da1 int doy = l_da1.getDayOfYear();// Display doySystem.out.println("l_da1.getDayOfYear(): " + doy);// Here, this method gets the value for// the field day-of-year in this// date object l_da2 doy = l_da2.getDayOfYear();// Display doySystem.out.println("l_da2.getDayOfYear(): " + doy);} }Output
輸出量
LocalDate l_da1 and l_da2: l_da1: 2007-04-05 l_da2: 2020-05-29l_da1.getDayOfYear(): 95 l_da2.getDayOfYear(): 150翻譯自: https://www.includehelp.com/java/localdate-getdayofyear-method-with-example.aspx
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的Java LocalDate类| 带示例的getDayOfYear()方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 怪物猎人崛起炎之封眼怎么解锁
- 下一篇: java两个文件夹比较路径_比较Java