其他分享
首页 > 其他分享> > 日历

日历

作者:互联网

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateDemo {
    public static void main(String[] args) {
        Date now = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
        String dataStr = simpleDateFormat.format(now);

        System.out.println("今天的日期是"+dataStr);
        System.out.println("今天的日期是"+now);


        Calendar calendar=Calendar.getInstance();
        System.out.println(calendar);
        System.out.println(calendar.getTime());
        System.out.println(calendar.get(Calendar.YEAR));
        System.out.println(calendar.get(Calendar.MONTH));//0是一月,少一个月
        System.out.println(calendar.get(Calendar.DAY_OF_WEEK));//星期天是第一天
        calendar.add(Calendar.MONTH,1);
        System.out.println("一个月后:"+calendar.getTime());
    }
}

 

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class TestCalendar {
    public static void main(String[] args) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
        Calendar calendar=Calendar.getInstance();
        calendar.set(2012,4,6);
        System.out.println(simpleDateFormat.format(calendar.getTime())+"是一年中的第"+calendar.get(Calendar.WEEK_OF_YEAR)+"星期");
    }
}

 

标签:日历,System,SimpleDateFormat,println,calendar,Calendar,out
来源: https://www.cnblogs.com/linlinmailbox/p/16491788.html