当前位置:网站首页>Calendar常用方法
Calendar常用方法
2022-07-21 11:09:00 【编程奥特曼.】
package itheima_02;
import java.util.Calendar;
/public abstract void add (int field, int amount): 根据日历的规则, 将指定的时间量添加或减去给定的日历字段
public final void set (int year, int month, int date):设置当前日历的年月日/
public class CalendarDamo {
public static void main(String[] args) {
//获取日历类对象
Calendar c = Calendar.getInstance();
//public int get(int field):返回给定日历字段的值
// int year = c.get(Calendar.YEAR);
// int month = c.get(Calendar.MONTH) + 1;
// int date = c.get(Calendar.DATE);
// System.out.println(year + “年” + month + “月” + date + “日”);
//public abstract void add (int field, int amount): 根据日历的规则, 将指定的时间量添加或减去给定的日历字段
//需求1:3年前的今天
// c.add(Calendar.YEAR,-3);
//
// int year = c.get(Calendar.YEAR);
// int month = c.get(Calendar.MONTH) + 1;
// int date = c.get(Calendar.DATE);
// System.out.println(year + “年” + month + “月” + date + “日”);
//需求2:10年后的5天前
// c.add(Calendar.YEAR,10);
// c.add(Calendar.DATE, -5);
//
// int year = c.get(Calendar.YEAR);
// int month = c.get(Calendar.MONTH) + 1;
// int date = c.get(Calendar.DATE);
// System.out.println(year + “年” + month + “月” + date + “日”);
// public final void set (int year, int month, int date):设置当前日历的年月日
c.set(2048,11,11);
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH) + 1;
int date = c.get(Calendar.DATE);
System.out.println(year + "年" + month + "月" + date + "日");
}
}
边栏推荐
猜你喜欢
生物制药安全供电保生产
UVM register model: reg adapter implementation and integration
这个可视化分析库,让你轻松玩转数据科学!
2022年7月31日DAMA-CDGA/CDGP数据治理认证班开启!
2020年文章汇总
Compilation Principle Experiment 1 -- principle and implementation of lexical analysis program design
Idea 2020.1 cancel parameter name display
Yii2 render custom template file
IDEA发布可运行的JAR包
大型体育场馆应急照明设计
随机推荐
Part 108 compound simple deployment
"F5g+eiot" build the energy Internet of things and help the data service of the power Internet of things
【2022年中总结】我走得很慢,但我从不后退
第101篇 盲盒智能合约(ERC1155)
Application of DC distribution system products at the end of data center
对图的广度优先遍历BFS和深度优先遍历DFS的应用——基于LeetCode133 克隆图
Part 101 blind box smart contract (erc1155)
訓練精度媲美 AlphaFold2、速度翻倍,飛槳螺旋槳HelixFold訓練和推理代碼全面開源...
The training accuracy is comparable to alphafold2, and the speed is doubled. The helixfold training and reasoning code of the propeller is fully open source
zooInspector 下载
JS部分
浅谈 Service Worker 在缓存资源以及Web Push上的应用
How to make the full-color LED display screen energy-saving and environmental protection?
初识数据库
记一次去除连接数限制问题
Advanced Fruits(公共子序列)
NPM and the development history of yarn
IDEA 2020.1 取消参数名称显示
对话ACE第四期:分布式数据库未来发展的挑战和机遇
Huawei machine test: imitating LISP operation