Calendar

Date date=new Date();
		Calendar calendar=Calendar.getInstance();
		calendar.setTime(date);
		System.out.println("year:" +calendar.get(Calendar.YEAR));
		System.out.println("month:"+calendar.get(Calendar.MONTH)+1);
		System.out.println("day:"+calendar.get(Calendar.DATE));
		System.out.println("day_of_week:"+calendar.get(Calendar.DAY_OF_WEEK));
		System.out.println("day_of_month:"+calendar.get(Calendar.DAY_OF_MONTH));
		System.out.println("day_of_year:"+calendar.get(Calendar.DAY_OF_YEAR));

Calendar.DATECalendar.DAY_OF_MONTH實際上是同樣的東西,Calendar.DATE文檔說明以下翻譯

Field number for get and set indicating the day of the month. This is a synonym for DAY_OF_MONTH. The first day of the month has value 1.code

翻譯過來就是:文檔

獲取和設置的字段號表示該月的日期。這是DAY_OF_MONTH的同義詞。本月的第一天價值爲1。get

相關文章
相關標籤/搜索