快速判断一天是星期几

时间:2021-12-10 18:06:44

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

/**
 * 快速判断一天是星期几
 *
 * @author Administrator
 *
 */
public class test02 {
 private static String[] WEEK = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
 public static void main(String[] args) throws ParseException {
  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  Calendar calendar = Calendar.getInstance();
  calendar.setTime(sdf.parse("2007-5-1"));
  System.out.println("这天是:"
    + WEEK[(calendar.get(Calendar.DAY_OF_WEEK) - 1)]);
 }
}