热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Java中的等时日期(int,int)方法,示例

Java 中的等时日期(int,int)方法,示例原文:https://www . geesforgeks . org/isoc

Java 中的等时日期(int,int)方法,示例

原文:https://www . geesforgeks . org/isochronomics-datyealdayint-int-method-in-Java-with-example/

Java . time . chrono . isochronology类的 dateYearDay() 方法用于根据特定年份和日期的 Iso 日历检索本地日期。

语法:

public LocalDate dateYearDay(int prolepticYear,
int dayOfYear)

参数:该方法以下列参数为参数:


  • 年:是 LocalDate 年字段的整数优先年

  • 日:是 LocalDate 的日字段的整数日

返回值:该方法根据特定年份和日期的 Iso 日历返回当地日期

以下是举例说明 dateYearDay() 方法的例子:

例 1:

Java 语言(一种计算机语言,尤用于创建网站)


// Java program to demonstrate
// dateYearDay() method
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
public class GFG {
    public static void main(String[] argv)
    {
        try {
            // creating and initializing LocalDate Object
            LocalDate hidate = LocalDate.now();
            // getting IsoChronology used in LocalDate
            IsoChronology crono = hidate.getChronology();
            // getting LocalDate for the
            // given date and year field
            // by using dateYearDay() method
            LocalDate date = crono.dateYearDay(1440, 24);
            // display the result
            System.out.println("LocalDate is: " + date);
        }
        catch (DateTimeException e) {
            System.out.println("passed parameter can "
                               + "not form a date");
            System.out.println("Exception thrown: " + e);
        }
    }
}

Output:

LocalDate is: 1440-01-24

例 2:

Java 语言(一种计算机语言,尤用于创建网站)


// Java program to demonstrate
// dateYearDay() method
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
public class GFG {
    public static void main(String[] argv)
    {
        try {
            // creating and initializing LocalDate Object
            LocalDate hidate = LocalDate.now();
            // getting IsoChronology used in LocalDate
            IsoChronology crono = hidate.getChronology();
            // getting LocalDate for the
            // given date and year field
            // by using dateYearDay() method
            LocalDate date = crono.dateYearDay(999999999, 32);
            // display the result
            System.out.println("LocalDate is: " + date);
        }
        catch (DateTimeException e) {
            System.out.println("passed parameter can "
                               + "not form a date");
            System.out.println("Exception thrown: " + e);
        }
    }
}

Output:

LocalDate is: +999999999-02-01

参考:https://docs . Oracle . com/javase/9/docs/API/Java/time/chrono/isochronomics . html # datyearday-int-int-


推荐阅读
author-avatar
手机用户2502940425
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有