欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

java Calendar类

程序员文章站 2022-03-19 21:37:23
public class CalendarDemo { public static void main(String[] args) { Date d = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy"); String ......

 

public class calendardemo {
    public static void main(string[] args) {
        date d = new date();
        simpledateformat sdf = new simpledateformat("yyyy");
        string year = sdf.format(d);
        system.out.println(year);

        calendar c = calendar.getinstance();
        //可以使用查表法月份查询
        system.out.println(c.get(calendar.year)+"年"+(c.get(calendar.month)+1)+"月"+c.get(calendar.day_of_month)+"日");
    }
}
public class calendardemo {
    public static void main(string[] args) {
        calendar c = calendar.getinstance();
        c.set(2012,2,23);
        system.out.println(c.get(calendar.year)+"年"+(c.get(calendar.month)+1)+"月"+c.get(calendar.day_of_month)+"日");
        c.add(calendar.year,-4);
        system.out.println(c.get(calendar.year)+"年"+(c.get(calendar.month)+1)+"月"+c.get(calendar.day_of_month)+"日");
    }
}