根据日期判断当前日期是周几

/**
     * 判断当前日期是星期几
     * 
     * @param  pTime     设置的需要判断的时间  //格式如2012-09-08
     *  


     * @return dayForWeek 判断结果
     * @Exception 发生异常
     */
    public static String getWeek(String pTime) {


 String Week = "星期";

 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
 Calendar c = Calendar.getInstance();
 try {
 c.setTime(format.parse(pTime));

 } catch (ParseException e) {
  e.printStackTrace();
 }
 if (c.get(Calendar.DAY_OF_WEEK) == 1) {
 Week += "日";
 }
 if (c.get(Calendar.DAY_OF_WEEK) == 2) {
 Week += "一";
 }
 if (c.get(Calendar.DAY_OF_WEEK) == 3) {
 Week += "二";
 }
 if (c.get(Calendar.DAY_OF_WEEK) == 4) {
 Week += "三";
 }
 if (c.get(Calendar.DAY_OF_WEEK) == 5) {
 Week += "四";
 }
 if (c.get(Calendar.DAY_OF_WEEK) == 6) {
 Week += "五";
 }
 if (c.get(Calendar.DAY_OF_WEEK) == 7) {
 Week += "六";
 }

 return Week;
}

你可能感兴趣的:(根据日期判断当前日期是周几)