廉頗老矣,尚能飯否

          java:從技術(shù)到管理

          常用鏈接

          統(tǒng)計(jì)

          最新評(píng)論

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

          //日期轉(zhuǎn)換成字符串
            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);
            
            //字符串轉(zhuǎn)換成日期
            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);//本月份的天數(shù)
            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 閱讀(1078) 評(píng)論(1)  編輯  收藏 所屬分類: 在路上

          評(píng)論

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

          您忘了導(dǎo)入包了  回復(fù)  更多評(píng)論   

          主站蜘蛛池模板: 美姑县| 新邵县| 雷波县| 武乡县| 喀什市| 杂多县| 同江市| 泽州县| 焦作市| 巫溪县| 绥棱县| 尤溪县| 库车县| 达日县| 元阳县| 乐都县| 长阳| 福贡县| 楚雄市| 天等县| 浦城县| 安阳县| 鄂托克前旗| 会昌县| 彩票| 文水县| 石棉县| 富阳市| 铁力市| 丰都县| 冀州市| 巴塘县| 陈巴尔虎旗| 嵩明县| 宣武区| 绥中县| 南丰县| 襄城县| 蒙山县| 五华县| 铁岭县|