廉頗老矣,尚能飯否

          java:從技術到管理

          常用鏈接

          統計

          最新評論

          java中日期與字符串格式的轉換(代碼片段)

          //日期轉換成字符串
            SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
            String now=format.format(new Date());
            System.out.println(now);
            
            String dateStr=format.format(format.parse("2007-12-12"));
            System.out.println(dateStr);
            
            //字符串轉換成日期
            Date date=format.parse("2007-12-12");
            System.out.println(date); 
            
            //求年月日
            Calendar time=Calendar.getInstance();
            time.clear();
            time.setTime(date);
            int year = time.get(Calendar.YEAR);
            int month = time.get(Calendar.MONTH) + 1;
            int day = time.get(Calendar.DAY_OF_MONTH);
            int maxDay=time.getActualMaximum(Calendar.DAY_OF_MONTH);//本月份的天數
            System.out.println(year);
            System.out.println(month);
            System.out.println(day);
            System.out.println(maxDay);

          柳德才
          13691193654
          18942949207
          QQ:422157370
          liudecai_zan@126.com
          湖北-武漢-江夏-廟山

          posted on 2009-01-13 11:28 liudecai_zan@126.com 閱讀(1074) 評論(1)  編輯  收藏 所屬分類: 在路上

          評論

          # re: java中日期與字符串格式的轉換(代碼片段) 2009-08-21 12:00 老人

          您忘了導入包了  回復  更多評論   

          主站蜘蛛池模板: 绵竹市| 繁峙县| 阳江市| 师宗县| 连城县| 秦皇岛市| 永年县| 尼木县| 岑溪市| 阜城县| 淮南市| 泌阳县| 西乌| 固原市| 都兰县| 青河县| 桑日县| 银川市| 台山市| 垦利县| 土默特右旗| 资阳市| 炎陵县| 漠河县| 乌苏市| 光山县| 长治市| 拉萨市| 饶河县| 弥勒县| 连云港市| 商南县| 新泰市| 巫山县| 延庆县| 广灵县| 乌兰浩特市| 同江市| 凌源市| 黄山市| 常山县|