日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

Java GregorianCalendar add()方法与示例

發(fā)布時間:2025/3/11 java 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java GregorianCalendar add()方法与示例 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

GregorianCalendar類的add()方法 (GregorianCalendar Class add() method)

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

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

  • add() method is used to add the given quantity to the specified GregorianCalendar field (fi).

    add()方法用于將給定數(shù)量添加到指定的GregorianCalendar字段(fi)。

  • add() 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.

    add()方法是一個非靜態(tài)方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。

  • add() method may throw an exception at the time of adding the given quantity to the given field (fi).

    在將給定量添加到給定字段(fi)時, add()方法可能會引發(fā)異常。

    IllegalArgumentException: This exception may throw when the given field (fi) is not in a range.

    IllegalArgumentException :如果給定字段(fi)不在范圍內(nèi),則可能引發(fā)此異常。

Syntax:

句法:

public void add(int fi , int quantity);

Parameter(s):

參數(shù):

  • int fi – represents the GregorianCalendar field.

    int fi –表示GregorianCalendar字段。

  • int quantity – represents the quantity of time to be added to the given calendar field.

    int數(shù)量 –表示要添加到給定日歷字段中的時間量。

Return value:

返回值:

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

此方法的返回類型為void ,不返回任何內(nèi)容。

Example:

例:

// Java program to demonstrate the example // of void add(int fi , int quantity) method of // GregorianCalendar import java.util.*;public class AddOfGregorianCalendar {public static void main(String[] args) {// Instantiating a GregorianCalendar objectGregorianCalendar g_ca = (GregorianCalendar) GregorianCalendar.getInstance();// Display current GregorianCalendarSystem.out.println("g_ca.getTime() : " + g_ca.getTime());// By using add() method is to substract 3 years// to the current GregorianCalendarg_ca.add(GregorianCalendar.YEAR, -3);// Display Update GregorianCalendarSystem.out.println("g_ca.add(GregorianCalendar.YEAR, -3): " + g_ca.getTime());// By using add() method is to add 5 months// to the current GregorianCalendarg_ca.add(GregorianCalendar.MONTH, 5);// Display Update CalendarSystem.out.println("g_ca.add(GregorianCalendar.MONTH, 3): " + g_ca.getTime());// By using add() method is to substract 2 days// to the current GregorianCalendarg_ca.add(GregorianCalendar.DATE, -2);// Display Update GregorianCalendarSystem.out.println("g_ca.add(GregorianCalendar.DATE, -2): " + g_ca.getTime());} }

Output

輸出量

g_ca.getTime() : Sat Feb 15 06:51:12 GMT 2020 g_ca.add(GregorianCalendar.YEAR, -3): Wed Feb 15 06:51:12 GMT 2017 g_ca.add(GregorianCalendar.MONTH, 3): Sat Jul 15 06:51:12 GMT 2017 g_ca.add(GregorianCalendar.DATE, -2): Thu Jul 13 06:51:12 GMT 2017

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

總結

以上是生活随笔為你收集整理的Java GregorianCalendar add()方法与示例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。