Java Calendar add()方法與示例

日歷類的add()方法 (Calendar Class add() method)

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

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

  • add() method is used to perform add or subtract the given amount of time to the given cal_fi (calendar field).

    add()方法用于對指定的cal_fi(日歷字段)執行相加或相減的時間量。

  • add() method is a non-static method, 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.

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

  • add() method does not throw an exception at the time of adding or subtracting the given time to a given calendar field.

    在給定日歷字段添加或減去給定時間時, add()方法不會引發異常。

Syntax:

句法:

    public abstract void add(int cal_fi, int  time);

Parameter(s):

參數:

  • int cal_fi – represents the calendar field.

    int cal_fi –代表日歷字段。

  • int amt – represents the amount of time to be added or subtracted to the calendar field.

    int amt –表示要添加或減去到日歷字段的時間。

Return value:

返回值:

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

該方法的返回類型為void ,不返回任何內容。

Example:

例:

// Java Program to demonstrate the example of
// void add(int cal_fi,int amt) method of Calendar
import java.util.*;
public class AddOfCalendar {
public static void main(String[] args) {
// Instantiating a Calendar object
Calendar ca = Calendar.getInstance();
// Display current calendar
System.out.println("ca.getTime(): " + ca.getTime());
// By using add() method is to substract 2 years
// to the current calendar
ca.add(Calendar.YEAR, -2);
// Display Update Calendar
System.out.println("cal.add(Calendar.YEAR, -2): " + ca.getTime());
// By using add() method is to add 2 months
// to the current calendar
ca.add(Calendar.MONTH, 2);
// Display Update Calendar
System.out.println("cal.add(Calendar.MONTH, 2): " + ca.getTime());
// By using add() method is to substract 2 days
// to the current calendar
ca.add(Calendar.DATE, -2);
// Display Update Calendar
System.out.println("cal.add(Calendar.DATE, -2): " + ca.getTime());
}
}

Output

輸出量

ca.getTime(): Thu Jan 23 11:06:12 GMT 2020
cal.add(Calendar.YEAR, -2): Tue Jan 23 11:06:12 GMT 2018
cal.add(Calendar.MONTH, 2): Fri Mar 23 11:06:12 GMT 2018
cal.add(Calendar.DATE, -2): Wed Mar 21 11:06:12 GMT 2018

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

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/377918.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/377918.shtml
英文地址,請注明出處:http://en.pswp.cn/news/377918.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

三、線性回歸實驗分析

所有代碼塊都是在Jupyter Notebook下進行調試運行,前后之間都相互關聯。 文中所有代碼塊所涉及到的函數里面的詳細參數均可通過scikit-learn官網API文檔進行查閱,這里我只寫下每行代碼所實現的功能,參數的調整讀者可以多進行試驗調試。多動手…

leetcode 236. 二叉樹的最近公共祖先 思考分析

目錄題目思考分析改進本文章代碼思路來源于公眾號【代碼隨想錄】題目 給定一個二叉樹, 找到該樹中兩個指定節點的最近公共祖先。 百度百科中最近公共祖先的定義為:“對于有根樹 T 的兩個結點 p、q,最近公共祖先表示為一個結點 x,滿足 x 是 p、…

輕輕松松給PCB板添加LOGO

在 PCB 圖中放置漢字或圖形的方法:A、文字——> 圖片——> PCB 圖——> 復制到自己作品中B、圖片——> PCB 圖——> 復制到自己作品中1、首先準備好“BMP”格式的圖片,在圖片中依靠顏色分辨圖層,所以最好準備“單色黑白”圖。…

java bitset_Java BitSet clone()方法及示例

java bitsetBitSet類clone()方法 (BitSet Class clone() method) clone() method is available in java.util package. clone()方法在java.util包中可用。 clone() method is used to clone this Bitset or in other words, this method is used to create a Bitset that is si…

小技巧

//屏蔽下拉框的某一個選項 <disabled"disable">... 1 <html>2 <body>3 4 <select>5 <option>Volvo</option>6 <option>Saab</option>7 <option disabled"disabled">Mercedes</option>…

jquery中text val html attr的差別

html和innerHTMl是一樣的&#xff0c;可以獲得和設置html標簽文本如&#xff1a;設置值&#xff1a;$("p").html("<span stylefont-size:13px;color:red>HTML標簽文本</span>"); 獲得值&#xff1a;$("p").html(); text和innerText是…

leetcode 235. 二叉搜索樹的最近公共祖先 思考分析

目錄題目思考迭代法題目 給定一個二叉搜索樹, 找到該樹中兩個指定節點的最近公共祖先。 百度百科中最近公共祖先的定義為&#xff1a;“對于有根樹 T 的兩個結點 p、q&#xff0c;最近公共祖先表示為一個結點 x&#xff0c;滿足 x 是 p、q 的祖先且 x 的深度盡可能大&#xff0…

四、邏輯回歸

邏輯回歸logistic_regression(LR)其實是分類算法&#xff0c;而不是回歸算法。 回歸算法得到的是一個數&#xff0c;分類算法得到的是幾個不同的類別。 邏輯回歸就是通過函數將值轉換為0-1之間&#xff0c;形成概率問題&#xff0c;從而實現了不同類別的分類。 Sigmoid 函數 …

db,dbms,dba_DBMS中的數據庫管理員(DBA)

db,dbms,dba數據庫管理員(DBA) (Database Administrator (DBA)) To use the Database Management System, it is necessary to have central control over data and programs together in order to access such data. A person who has central control over such system is re…

運算符優先級

轉載于:https://www.cnblogs.com/c-cloud/p/3280911.html

五、邏輯回歸實驗分析

所有代碼塊都是在Jupyter Notebook下進行調試運行&#xff0c;前后之間都相互關聯。 文中所有代碼塊所涉及到的函數里面的詳細參數均可通過scikit-learn官網API文檔進行查閱&#xff0c;這里我只寫下每行代碼所實現的功能&#xff0c;參數的調整讀者可以多進行試驗調試。多動手…

二叉搜索樹的插入、刪除、修剪、構造操作(leetcode701、450、669、108)

目錄1、leetcode 701. 二叉搜索樹中的插入操作1、題目2、遞歸法3、迭代法2、leetcode 450. 二叉搜索樹中的插入操作1、題目2、思路遞歸法3、迭代法4、刪除結點的兩個方法以及注意點3、leetcode 669. 修剪二叉搜索樹1、題目2、思考與遞歸3、迭代法4、leetcode 108. 將有序數組轉…

Memcached查看和清理

1.一種telnet localhost 11211 #登陸stats #查看狀態flush_all #清理quit #退出2.又學到一個:echo flush_all | nc localhost 112113.1、數據存儲(假設key為test,value為12345) printf "set test 0 1 5\r\n12345\r\n" | nc localhost 11211STORED2.數據取回(假設key為…

模擬退火算法解決np_P和NP問題與解決方案| 演算法

模擬退火算法解決npP問題 (P Problems) P is the set of all the decision problems solvable by deterministic algorithms in polynomial time. P是多項式時間內確定性算法可解決的所有決策問題的集合。 NP問題 (NP Problems) NP is the set of all the decision problems t…

POJ2251Dungeon Master

http://poj.org/problem?id2251 題意 &#xff1a; 就是迷宮升級版&#xff0c;從以前的一個矩陣也就是一層&#xff0c;變為現在的L層&#xff0c;" . "是可以走&#xff0c;但是“#”不可以走&#xff0c;從S走到E&#xff0c;求最短的路徑&#xff0c;若是找不到…

六、聚類算法

一、聚類概念 1&#xff0c;通俗易懂而言&#xff0c;聚類主要運用于無監督學習中&#xff0c;也就是將沒有標簽的東西如何分為幾堆兒。 2&#xff0c;無監督學習即沒有標簽&#xff0c;不知道這些玩意到底是啥。當然&#xff0c;有監督學習就是由標簽&#xff0c;我們是提前知…

Apache服務器通過.htaccess文件設置防盜鏈

用戶經常面對的一個問題就是服務器的流量問題&#xff0c;而站點文件被盜鏈是其中最為主要的部分。所謂盜鏈&#xff0c;是指其他網站直接鏈接我們網站上的文件&#xff0c;一般來 說&#xff0c;盜鏈的對象大多為很耗帶寬的大體積文件&#xff0c;如圖片、視頻等。這樣造成的后…

【C++grammar】string類和array類

目錄1、C11的string類1、創建 string 對象2、追加字符串append函數3、為字符串賦值assign函數4、at, clear, erase, and empty函數5、比較字符串compare()6、獲取子串at() 、substr()函數7、搜索字符串find()8、插入和替換字符串insert() 、replace()9、字符串運算符10、string…

六、聚類算法實戰

所有代碼塊都是在Jupyter Notebook下進行調試運行&#xff0c;前后之間都相互關聯。 文中所有代碼塊所涉及到的函數里面的詳細參數均可通過scikit-learn官網API文檔進行查閱&#xff0c;這里我只寫下每行代碼所實現的功能&#xff0c;參數的調整讀者可以多進行試驗調試。多動手…

超圖軟件試用許可操作步驟_軟件中的操作步驟

超圖軟件試用許可操作步驟The software comprises of three things: Program code, Documentation, and the Operating Procedures. The Program code is the entire software code. The Documentation is produced while the development of the software itself for the time…