28.4 Calendar 日历

/*
* Calendar:日历,提供了一些操作年月日时的方法
* 获取
* 修改
* 添加
*/

public class CalendarDemo {
    public static void main(String[] args) {
        Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR); int month = c.get(Calendar.MONTH) + 1; //月份是从0开始计起,所以当前月应该+1 int day = c.get(Calendar.DAY_OF_MONTH); System.out.println(year+","+month+","+day); c.set(Calendar.DAY_OF_MONTH,2);//把指定的字段修改成指定的值 int day2 = c.get(Calendar.DAY_OF_MONTH); System.out.println(day2); c.add(Calendar.DAY_OF_MONTH,15);//在指定的字段上加上指定的值 int day3 = c.get(Calendar.DAY_OF_MONTH); System.out.println(day3); } }

 

输出

 

posted @ 2019-07-26 18:10  龙桑  阅读(153)  评论(0编辑  收藏  举报