廉頗老矣,尚能飯否

          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 閱讀(1072) 評論(1)  編輯  收藏 所屬分類: 在路上

          評論

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

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

          主站蜘蛛池模板: 吉首市| 钦州市| 肃宁县| 灯塔市| 平塘县| 平罗县| 商都县| 固镇县| 嘉定区| 灵石县| 手游| 扎囊县| 申扎县| 普宁市| 洪湖市| 罗山县| 新干县| 汽车| 灌阳县| 芮城县| 鄢陵县| 盐池县| 浦东新区| 清水县| 浙江省| 隆安县| 津南区| 明溪县| 鄂州市| 武定县| 灵武市| 连南| 东乡| 中西区| 昌图县| 务川| 会泽县| 兴业县| 浮梁县| 海阳市| 密山市|