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
Java Calendar add()方法与示例相关推荐
- cdate在java中_Java Calendar.add方法代码示例
本文整理汇总了Java中java.util.Calendar.add方法的典型用法代码示例.如果您正苦于以下问题:Java Calendar.add方法的具体用法?Java Calendar.add怎 ...
- java calendar.add方法_Java Calendar add()方法与示例
日历类add()方法add()方法在java.util包中可用. add()方法用于对指定的cal_fi(日历字段)执行相加或相减的时间量. add()方法是一个非静态方法,可通过类对象访问,如果尝试 ...
- java arraylist.add(),Java ArrayList add()方法与示例
ArrayList类add()方法 语法:public boolean add(T ele); public void add(int indices, T ele);add()方法在java.uti ...
- Java Calendar.add()方法的使用,参数含义。指定时间差。
cal.add()方法中的参数含义: 第一个参数如果是1则代表的是对年份操作,2是对月份操作,3是对星期操作,5是对日期操作,11是对小时操作,12是对分钟操作,13是对秒操作,14是对毫秒操作. 第 ...
- Java IOUtils.copy方法代码示例(亲测)
本文整理汇总了Java中org.apache.commons.io.IOUtils.copy方法的典型用法代码示例.如果您正苦于以下问题:Java IOUtils.copy方法的具体用法?Java I ...
- Java List.add()方法
Java List.add()方法 Java 集合类中的 List.add() 方法用于向集合列表中添加对象. 语法1 add(A) 用于在列表的尾部插入指定元素.如果 List 集合对象由于调用 a ...
- java的add方法的使用_Java HashSet add()方法与示例
HashSet类add()方法add()方法在java.util包中可用. 当尚不存在给定元素时,使用add()方法将其插入此HashSet中,否则它将忽略它并返回false. add()方法是一种非 ...
- java中如何使用add方法_使用Java中的Calendar.add()方法将秒添加到当前日期
为Java中的Calendar类导入以下软件包.import java.util.Calendar; 首先,创建一个Calendar对象并显示当前日期和时间.Calendar calendar = C ...
- Calendar导入java,Java程序使用Calendar.add()方法将分钟添加到当前时间
为Java中的Calendar类导入以下软件包.import java.util.Calendar; 首先,创建一个Calendar对象并显示当前日期和时间.Calendar calendar = C ...
最新文章
- 互联网技术都应该了解的一种数据格式——JSON
- 学编程当中最重要的三点,一些很正经的建议
- nginx配置websocket代理
- MVC5+EF6 入门完整教程七
- html 文件上传与移除,js jquery分别实现动态的文件上传操作按钮的添加和删除
- android jni 返回java类
- manjaro Linux调节屏幕显示亮度
- WinCE 控制面板的创建
- net core体系-web应用程序-4asp.net core2.0 项目实战(1)-11项目日志解决方案
- Ruby中的类与对象(一)
- python快速上手_Python快速上手(一)
- 单应性(同义词直射变换、射影变换和射影性等)(来自wiki)
- 后台管理系统之题库管理
- Android最新API获取北斗卫星定位信息(全网最新)
- 切换无线网卡失败服务器提示,电脑无线网卡切换为AP模式时提示ICS启动失败的解决方法...
- 网线水晶头制作及标准接法教程,新手必备技能
- 《地狱是上帝不在的地方》
- 用于拆解和组合PDF中各个对象的shell脚本
- 思科路由器重置密码并保存设置重置密码
- linux 获取优盘设备序列号变为小写再用MD5加密