java學習

          java學習

           

          java由年份和月份得到這個月有多少天

           public static int getDaysByMonth(String time){
                   Calendar rightNow = Calendar.getInstance();

                   SimpleDateFormat simpleDate = new SimpleDateFormat("yyyy-MM"); //如果寫成年月日的形式的話,要寫小d,如:"yyyy/MM/dd"

                   try {

                   rightNow.setTime(simpleDate.parse(time)); //要計算你想要的月份,改變這里即可

                   } catch (Exception e) {

                   e.printStackTrace();

                   }

                   int days = rightNow.getActualMaximum(Calendar.DAY_OF_MONTH);
          return days;
                  
               }

               public static List<String> getWeekDay(String str) {
                   List<String> list = new ArrayList<String>();
                   Calendar c = Calendar.getInstance();
                     SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                     Date date = null;
                  try {
                      date = sdf.parse(str);
                  } catch (ParseException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  }
                     c.setTime(date);
                     int week = c.get(Calendar.WEEK_OF_MONTH);//獲取是本月的第幾周
                     System.out.println("今天是本月的第" + week + "周");
                      String nReturn;
                      switch (c.get(Calendar.DAY_OF_WEEK)) {
                      case 1:
                          nReturn = "7";
                          break;
                      case 2:
                          nReturn = "1";
                          break;
                      case 3:
                          nReturn = "2";
                          break;
                      case 4:
                          nReturn = "3";
                          break;
                      case 5:
                          nReturn = "4";
                          break;
                      case 6:
                          nReturn = "5";
                          break;
                      case 7:
                          nReturn = "6";
                          break;
                      default:
                          nReturn = null;
                          break;
                      }
                      list.add(String.valueOf(String.valueOf(week)));
                      list.add(nReturn);
                      System.out.println(nReturn);
                      return list;
                  }

          posted on 2013-03-08 16:42 楊軍威 閱讀(1172) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          導航

          統計

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 万荣县| 仪征市| 高青县| 唐海县| 西乌珠穆沁旗| 仁怀市| 阜南县| 无极县| 藁城市| 聊城市| 沽源县| 吉林省| 荆州市| 德庆县| 江达县| 铁力市| 平泉县| 长白| 平山县| 察雅县| 高唐县| 专栏| 兰州市| 府谷县| 洪湖市| 汾西县| 三穗县| 理塘县| 龙海市| 天水市| 东乡族自治县| 广昌县| 海晏县| 四子王旗| 黄平县| 曲周县| 凤城市| 怀集县| 南阳市| 水富县| 长阳|