Java LocalDate类| of()方法与示例

LocalDate类的()方法 (LocalDate Class of() method)

Syntax:

句法:

public static LocalDate of(int yyyy, int mm, int day_of_mon);
public static LocalDate of(int yyyy, Month mm, int day_of_mon);

  • of() method is available in java.time package.

    of()方法在java.time包中可用。

  • of(int yyyy, int mm, int day_of_mon) method is used to create an instance of LocalDate object from the given parameter year, month and day-of-month.

    of(int yyyy,int mm,int day_of_mon)方法用于根据给定的参数year,month和day-of-month创建LocalDate对象的实例。

  • of(int yyyy, Month mm, int day_of_mon) method is used to create an instance of LocalDate object from the given parameter year, Month and day-of-month.

    of(int yyyy,Month mm,int day_of_mon)方法用于根据给定的参数year,Month和month-of-month创建LocalDate对象的实例。

  • These methods don’t throw an exception at the time of represent date.

    这些方法在表示日期时不会引发异常。

  • These are static methods and it is accessible with class name and if we try to access these methods with class object then we will not get an error.

    这些是静态方法,可通过类名进行访问,如果尝试使用类对象访问这些方法,则不会出错。

Parameter(s):

参数:

  • In the first cases, of(int yyyy, int mm, int day_of_mon),

    在(int yyyy,int mm,int day_of_mon)的第一种情况下,

    • int yyyy – represents the year to denote this object and the range of year starts from MIN_YEAR to MAX_YEAR.
    • int yyyy –代表表示该对象的年份,年份范围从MIN_YEAR到MAX_YEAR。
    • int mm – represents the month of year to denote this object and the number of months in a year starts from 1 and ends at 12.
    • int mm –表示表示该对象的月份,一年中的月份数从1开始,以12结尾。
    • int day_of_mon – represents the day-of-month to denote this object and the number of days in a month starts from 1 and ends at 31.
    • int day_of_mon –表示表示该对象的月份中的天,一个月中的天数从1开始,以31结尾。
  • In the second cases, of(int yyyy, Month mm, int day_of_mon),

    在第二种情况下,of(int yyyy,Month mm,int day_of_mon),

    • int yyyy – Similar as defined in the first case.
    • int yyyy –与第一种情况下定义的相似。
    • Month mm – represents the month of year defined in enum Month.
    • 月mm –代表枚举月中定义的一年中的月份。
    • int day_of_mon – Similar as defined in the first case.
    • int day_of_mon –与第一种情况下定义的相似。

Return value:

返回值:

In both the cases, the return type of the method is LocalDate, it returns an instance of LocalDate created from the given parameters.

在这两种情况下,方法的返回类型均为LocalDate ,它返回从给定参数创建的LocalDate实例。

Example:

例:

// Java program to demonstrate the example 
// of of() method of LocalDate

import java.time.*;

public class OfLocalDate {
    public static void main(String args[]) {
        int year = 2005;
        int day_of_month = 10;
        int month = 5;

        // Here, of(int,int,int) creates a 
        // LocalDate from a year, month and
        // day-of-month
        LocalDate l_da = LocalDate.of(year, month, day_of_month);

        // Display l_da
        System.out.println("LocalDate.of(year,month,day_of_month): " + l_da);

        // Here, of(int,Month,int) creates a
        // LocalDate from a year, Month and 
        // day-of-month
        l_da = LocalDate.of(year, Month.JUNE, day_of_month);

        // Display l_da
        System.out.println("LocalDate.of(year,Month.JUNE,day_of_month): " + l_da);
    }
}

Output

输出量

LocalDate.of(year,month,day_of_month): 2005-05-10
LocalDate.of(year,Month.JUNE,day_of_month): 2005-06-10


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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值