Java小练:用Calendar类获取今天是星期几

package com.java1234.chap05.sec01;

import java.util.Calendar;
import java.util.Date;

/*
 *用Calendar类获取今天是星期几 
 */
public class CalendarHomeWork {
	
	public static void main(String[] args) {
		String []arr = {"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
		Calendar calendar = Calendar.getInstance();
		System.out.println("今天是:"+arr[calendar.get(Calendar.DAY_OF_WEEK)-1]); //1.数组下标从0开始;2.老外的第一天是从星期日开始的
	}
}

 

你可能感兴趣的:(Java小练习)