当前位置:网站首页>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());
}
}边栏推荐
- Implement the redis simple client customized based on socket
- [cloud resident co creation] ModelBox draws your own painting across the air
- IDEA Dashboard
- Berkeley, MIT, Cambridge, deepmind et d'autres grandes conférences en ligne: vers une IA sûre, fiable et contrôlable
- 2021-09-30
- Internet of things? Come and see Arduino on the cloud
- Leetcode(455)——分发饼干
- Background of master data construction
- Basic properties and ergodicity of binary tree
- Leetcode (135) - distribute candy
猜你喜欢

Visitor model -- generation gap between young and middle-aged people
![Use the transparent [x] cross button image in the dialog](/img/0c/2be7bc7f20b581a2cc745d9cabe9ff.jpg)
Use the transparent [x] cross button image in the dialog

Image panr

Stackoverflow 年度报告 2022:开发者最喜爱的数据库是什么?

Otaku can't save yuan universe

After idea installs these plug-ins, the code can be written to heaven. My little sister also has to arrange it

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

物联网?快来看 Arduino 上云啦

More than ten years' work experience is recommended at the bottom of the box: how much does it cost to find a job? See here! Brothers and sisters are recommended to collect and pay attention

Mapstacks: data normalization and layered color layer loading
随机推荐
Material management system based on SSM (source code + document + database)
基于SSM的物料管理系统(源码+文档+数据库)
Why do we always "give up halfway"?
Is the waiting insurance record a waiting insurance evaluation? What is the relationship between the two?
京东一面:Redis 如何实现库存扣减操作?如何防止商品被超卖?
Leetcode(455)——分发饼干
How to enhance influence
Summary of idea practical skills: how to rename a project or module to completely solve all the problems you encounter that do not work. It is suggested that the five-star collection be your daughter
[multi thread performance tuning] multi thread lock optimization (Part 1): optimization method of synchronized synchronization lock
What will you do if you have been ignored by your leaders at work?
More than ten years' work experience is recommended at the bottom of the box: how much does it cost to find a job? See here! Brothers and sisters are recommended to collect and pay attention
Background of master data construction
“拯救”直播带货,一个董宇辉还不够
Can the OPDS SQL component pass process parameters to the next component through context
网络安全审查办公室对知网启动网络安全审查
年轻人捧红的做饭生意经:博主忙卖课带货,机构月入百万
基于QT+MySQL的相机租赁管理系统
[cloud resident co creation] ModelBox draws your own painting across the air
Leetcode (146) - LRU cache
使用gorm查询数据库时reflect: reflect.flag.mustBeAssignable using unaddressable value