android 根據設置的日期獲取星期幾

 /**
  * 判斷當前日期是星期幾
  *
  * @param  pTime     設置的需要判斷的時間  //格式如2012-09-08
  *  

  * @return dayForWeek 判斷結果
  * @Exception 發生異常
  */

//  String pTime = "2012-03-12";
 private 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) {
   // TODO Auto-generated catch block
   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;
 }

發佈了63 篇原創文章 · 獲贊 8 · 訪問量 9萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章