当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java MinguoDate of(int, int, int)用法及代码示例


java.time.chrono.MinguoDate类的of()方法用于根据Minguo日历系统,使用传递的通行年份,月份和日期来生成日期。

用法:

public static MinguoDate of(int Year,
            int month, int dayOfMonth)

参数:此方法将以下参数作为参数:



  • year:是year的整数值,代表Minguo日期中的year字段。
  • month:这是month的整数值,代表Minguo日期中的month字段。
  • day:是day的整数值,代表Minguo日期中的day字段。

返回值:此方法根据使用的传递的年份,月份和日期,根据Minguo日历系统返回日期。

异常:如果传递的参数无法形成日期,则此方法将引发DateTimeException。

下面的示例说明了of()方法:

范例1:

Java

// Java program to demonstrate of() method 
  
import java.util.*; 
import java.io.*; 
import java.time.*; 
import java.time.chrono.*; 
import java.time.temporal.*; 
  
public class GFG { 
    public static void main(String[] argv) 
    { 
        try { 
  
            // Creating and initializing 
            // MinguoDate Object 
            // By using of() method 
            MinguoDate hidate 
                = MinguoDate.of(1444, 04, 24); 
  
            // Display the result 
            System.out.println("MinguoDate:"
                               + hidate); 
        } 
        catch (DateTimeException e) { 
            System.out.println("passed parameter can"
                               + " not form a date"); 
            System.out.println("Exception thrown:"
                               + e); 
        } 
    } 
}
输出:
MinguoDate:Minguo ROC 1444-04-24

范例2:

Java

// Java program to demonstrate of() method 
  
import java.util.*; 
import java.io.*; 
import java.time.*; 
import java.time.chrono.*; 
import java.time.temporal.*; 
  
public class GFG { 
    public static void main(String[] argv) 
    { 
        try { 
  
            // Creating and initializing 
            // MinguoDate Object 
            // By using of() method 
            MinguoDate hidate 
                = MinguoDate.of(1911, 04, -24); 
  
            // Display the result 
            System.out.println("MinguoDate:"
                               + hidate); 
        } 
        catch (DateTimeException e) { 
            System.out.println("passed parameter can"
                               + " not form a date"); 
            System.out.println("Exception thrown:"
                               + e); 
        } 
    } 
}
输出:
passed parameter can not form a date
Exception thrown:
 java.time.DateTimeException:
 Invalid value for DayOfMonth (valid values 1 - 28/31):-24

参考: https://docs.oracle.com/javase/9/docs/api/java/time/chrono/MinguoDate.html#of-int-int-int-




相关用法


注:本文由纯净天空筛选整理自RohitPrasad3大神的英文原创作品 MinguoDate of(int, int, int) method in Java with Example。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。