Java GregorianCalendar setGregorianChange()方法与示例

GregorianCalendar类setGregorianChange()方法 (GregorianCalendar Class setGregorianChange() method)

  • setGregorianChange() method is available in java.util package.

    setGregorianChange()方法在java.util包中可用。

  • setGregorianChange() method is used to assign the GregorianCalendar change date from Julian to gregorian dates.

    setGregorianChange()方法用于将GregorianCalendar更改日期从儒略日分配给gregorian日期。

  • setGregorianChange() method is a non-static method, so it is accessible with the class object and if we try to access the method with the class name then we will get an error.

    setGregorianChange()方法是一种非静态方法,因此可以通过类对象进行访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • setGregorianChange() method does not throw an exception at the time of the set gregorian calendar date.

    setGregorianChange()方法在设置公历日期时不会引发异常。

Syntax:

句法:

    public void setGregorianChange(Date d);

Parameter(s):

参数:

  • Date d – represent the GregorianCalendar date.

    日期d –表示公历日期。

Return value:

返回值:

The return type of the method is void, it returns nothing.

该方法的返回类型为void ,不返回任何内容。

Example:

例:

// Java program is to demonstrate the example of
// setGregorianChange(Date d) method of Calendar

import java.util.*;

public class SetGregorianChange {
    public static void main(String[] args) {
        // Instantiates a GregorianCalendar object
        GregorianCalendar ca = (GregorianCalendar) GregorianCalendar.getInstance();
        Date d = new Date(98, 04, 20);

        // Display current GregorianCalendar
        System.out.println("ca: " + ca.getTime());

        // By using getGregorianChange() method isto
        // change the gregorian calendar date
        System.out.print("ca.getGregorianChange(): ");
        System.out.println(ca.getGregorianChange());

        // By using setGregorianChage() method isto
        // set the GregorianChange date
        ca.setGregorianChange(d);

        // By using getGregorianChange() method isto
        // get the change gregorian calendar date
        System.out.print("ca.setGregorianChange(d): ");
        System.out.println(ca.getGregorianChange());
    }
}

Output

输出量

ca: Sat Feb 15 12:53:31 GMT 2020
ca.getGregorianChange(): Fri Oct 15 00:00:00 GMT 1582
ca.setGregorianChange(d): Wed May 20 00:00:00 GMT 1998


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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值