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 LocalDate

import java.time.*;

public class GetDayOfYearOfLocalDate {
    public static void main(String args[]) {
        // Instantiates two LocalDate
        LocalDate l_da1 = LocalDate.parse("2007-04-05");
        LocalDate l_da2 = LocalDate.now();

        // Display l_da1,l_da2
        System.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 doy
        System.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 doy
        System.out.println("l_da2.getDayOfYear(): " + doy);
    }
}

Output

输出量

LocalDate l_da1 and l_da2: 
l_da1: 2007-04-05
l_da2: 2020-05-29

l_da1.getDayOfYear(): 95
l_da2.getDayOfYear(): 150


翻译自: https://www.includehelp.com/java/localdate-getdayofyear-method-with-example.aspx

获取当天日期 获取本周一日期 获取本周日的日期 获取上周一日期:" + tt.getPreviousWeekday("yyyy-MM-dd")); 获取上周日日期:" + tt.getPreviousWeekSunday("yyyy-MM-dd")); 获取上周一日期:" + tt.getWeekday(-1, "yyyy-MM-dd")); 获取上周日日期:" + tt.getWeekSunday(-1, "yyyy-MM-dd")); 获取下周一日期:" + tt.getNextMonday("yyyy-MM-dd")); 获取下周日日期:" + tt.getNextSunday("yyyy-MM-dd")); 获取本月第一天日期:" + tt.getFirstDayOfMonth()); 获取本月最后一天日期:" + tt.getDefaultDay()); 获取上月第一天日期:" + tt.getPreviousMonthFirst("yyyy-MM-dd")); 获取上月最后一天的日期:" + tt.getPreviousMonthEnd("yyyy-MM-dd")); 获取某月第一天日期:" + tt.getMonthFirst(0, "yyyy-MM-dd")); 获取某月最后一天的日期:" + tt.getMonthEnd(0, "yyyy-MM-dd")); 获取下月第一天日期:" + tt.getNextMonthFirst("yyyy-MM-dd")); 获取下月最后一天日期:" + tt.getNextMonthEnd("yyyy-MM-dd")); 获取本年的第一天日期:" + tt.getCurrentYearFirst()); 获取本年最后一天日期:" + tt.getCurrentYearEnd()); 获取去年的第一天日期:" + tt.getPreviousYearFirst()); 获取去年的最后一天日期:" + tt.getPreviousYearEnd()); 获取明年第一天日期:" + tt.getNextYearFirst()); 获取明年最后一天日期:" + tt.getNextYearEnd()); 获取本季度第一天:" + tt.getThisSeasonFirstTime(11)); 获取本季度最后一天:" + tt.getThisSeasonFinallyTime(11)); 获取两个日期之间间隔天数 获取当前月的第几周:" + tt.getWeekOfMonth()); 获取当前年份:" + tt.getYear()); 获取当前月份:" + tt.getMonth()); 获取今天在本年的第几天:" + tt.getDayOfYear()); 获得今天在本月的第几天(获得当前日):" + tt.getDayOfMonth()); 获得今天在本周的第几天:" + tt.getDayOfWeek()); 字符串转时间 获得一个日期所在周的星期几的日期
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值