当前位置:网站首页>Common member methods of the calendar class
Common member methods of the calendar class
2022-06-24 20:57:00 【Platonic】
| void add(int field, int amount) | For the given calendar field field Add or subtract the specified amount of time amount |
| int get(int field) | int get(int field) |
| static Calendar getInstance() | static Calendar getInstance() |
| Date getTime() | Return a representation of this Calendar Time is worth Date object |
Example :
public class Demo02Calendar {
public static void main(String[] args) {
//demo02();
// demo01();
//demo03();
demo04();
}
/*public int get(int field): Returns the value of the given calendar field
* Parameters : Pass the specified calendar field (YEar,MONTH..)
* Return value : Calendar fields represent specific values
* */
private static void demo01(){
// Use getInstance Method to get Calendar() object
Calendar c=Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH)+1;
int date= c.get(Calendar.DATE);
System.out.println(year+" year ");
System.out.println(month+" month ");
System.out.println(date+" Japan ");
}
//public void set(int field,int value): Set the given calendar field to the given value
private static void demo02(){
// Use getInstance Method to get Calendar() object
Calendar c=Calendar.getInstance();
c.set(Calendar.YEAR,2021);
c.set(Calendar.MONTH,2);
c.set(Calendar.DATE,21);
// You can also set the year, month and day at the same time
// c.set(2021,2,21);
System.out.println();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int date= c.get(Calendar.DATE);
System.out.println(year+" year ");
System.out.println(month+" month ");
System.out.println(date+" Japan ");
}
//public abstract void add(int field,int value): Add and subtract specific values ;
private static void demo03(){
// Use getInstance Method to get Calendar() object
Calendar c=Calendar.getInstance();
c.add(Calendar.YEAR,2);
c.add(Calendar.MONTH,2);
c.add(Calendar.DATE,1);
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int date= c.get(Calendar.DATE);
System.out.println(year+" year ");
System.out.println(month+" month ");
System.out.println(date+" Japan ");
}
public static void demo04(){
// Use getInstance Method to get Calendar() object
Calendar c=Calendar.getInstance();
Date time = c.getTime();
System.out.println(time);
System.out.println(time.toLocaleString());
}
}边栏推荐
- Map跟object 的区别
- 伯克利、MIT、剑桥、DeepMind等业内大佬线上讲座:迈向安全可靠可控的AI
- C language to realize mine sweeping (simple version)
- 图像PANR
- Leetcode (455) - distribute cookies
- Bytebase加入阿里云PolarDB开源数据库社区
- Tool composition in JMeter
- 红象云腾完成与龙蜥操作系统兼容适配,产品运行稳定
- How to apply agile development ideas to other work
- 年轻人捧红的做饭生意经:博主忙卖课带货,机构月入百万
猜你喜欢

Vant component used in wechat applet

Berkeley, MIT, Cambridge, deepmind et d'autres grandes conférences en ligne: vers une IA sûre, fiable et contrôlable

微信小程序中使用vant组件

Cooking business experience of young people: bloggers are busy selling classes and bringing goods, and the organization earns millions a month

得物多活架构设计之路由服务设计

Apple doesn't need money, but it has no confidence in its content

实现基于Socket自定义的redis简单客户端

Implement the redis simple client customized based on socket

基于SSM的物料管理系统(源码+文档+数据库)

Agency mode -- Jiangnan leather shoes factory
随机推荐
Haitai Advanced Technology | application of privacy computing technology in medical data protection
Can the OPDS SQL component pass process parameters to the next component through context
Why do we always "give up halfway"?
苹果、微软、谷歌不再掐架,今年要合力干一件大事
Smooth live broadcast | analysis of key technologies for live broadcast pain points
Leetcode (135) - distribute candy
Hosting service and SASE, enjoy the integration of network and security | phase I review
The AI for emotion recognition was "harbouring evil intentions", and Microsoft decided to block it!
Intermediary model -- collaboration among departments
Two fellow countrymen from Hunan have jointly launched a 10 billion yuan IPO
The difference between RPC and restful
CVPR 2022缅怀孙剑!同济、阿里获最佳学生论文奖,何恺明入围
A/B测试助力游戏业务增长
Wechat applet custom tabbar
RF_ DC system clock setting gen1/gen2
How to enhance influence
When querying the database with Gorm, reflect: reflect flag. mustBeAssignable using unaddressable value
Jd.com: how does redis implement inventory deduction? How to prevent oversold?
字节、腾讯也下场,这门「月赚3000万」的生意有多香?
对“宁王”边卖边买,高瓴资本“高抛低吸”已套现数十亿