首页 > 代码库 > Date和Calendar

Date和Calendar

import java.util.Calendar;
import java.util.Date;
public class shijian {
    public static void main(String[] args) {
Calendar c=Calendar.getInstance();
//修改,获取,增加
//System.out.println(c.get(Calendar.YEAR));
//System.out.println(c.get(Calendar.MONTH)+1);
//System.out.println(c.get(Calendar.DATE));
//System.out.println(c.get(Calendar.HOUR_OF_DAY));
//System.out.println(c.get(Calendar.MINUTE));
//System.out.println(c.get(Calendar.DAY_OF_WEEK));
////英文一周的第一天是周日
//System.out.println(c.get(Calendar.DAY_OF_YEAR));
//c.set(Calendar.YEAR,2020);
//c.set(1995, 10, 30);
c.add(Calendar.YEAR, -6);
System.out.println(c.getTime());
Calendar cc=Calendar.getInstance();
cc.setTime(new Date());

    }
}

 

Date和Calendar