一個用來獲得日期信息的實用類

          /*
           *@author 我為J狂 建立日期 2007-4-20
           *
           
          */

          package net.blogjava.lzqdiy;

          import java.util.Calendar;
          import java.util.GregorianCalendar;

          public class DateInf
          {
              Calendar now 
          = new GregorianCalendar();

              String year;

              String month;

              String date;

              
          // 得到當前日期
              public DateInf()
              
          {
                  year 
          = String.valueOf(now.get(Calendar.YEAR));
                  
          if ((now.get(Calendar.MONTH) + 1<= 9)
                      month 
          = String.valueOf("0" + (now.get(Calendar.MONTH) + 1));
                  
          else
                      month 
          = String.valueOf(now.get(Calendar.MONTH) + 1);
                  
          if (now.get(Calendar.DATE) <= 9)
                      date 
          = String.valueOf("0" + now.get(Calendar.DATE));
                  
          else
                      date 
          = String.valueOf(now.get(Calendar.DATE));
              }


              
          // 得到n天后的日期
              public DateInf(int n)
              
          {
                  java.util.Date myDate 
          = new java.util.Date();

                  
          long myTime = (myDate.getTime() / 1000+ n * 60 * 60 * 24;
                  myDate.setTime(myTime 
          * 1000);
                  now.setTime(myDate);
                  year 
          = String.valueOf(now.get(Calendar.YEAR));
                  
          if ((now.get(Calendar.MONTH) + 1<= 9)
                      month 
          = String.valueOf("0" + (now.get(Calendar.MONTH) + 1));
                  
          else
                      month 
          = String.valueOf(now.get(Calendar.MONTH) + 1);
                  
          if (now.get(Calendar.DATE) <= 9)
                      date 
          = String.valueOf("0" + now.get(Calendar.DATE));
                  
          else
                      date 
          = String.valueOf(now.get(Calendar.DATE));
              }


              String getYear()
              
          {
                  
          return year;
              }


              String getMonth()
              
          {
                  
          return month;
              }


              String getDate()
              
          {
                  
          return date;
              }


              String getDateInf()
              
          {
                  
          return year + "." + month + "." + date;// 例如:"2006.05.11"
              }

              
          public static void main(String[] args)
              
          {
                  DateInf now
          =new DateInf();
                  
          //輸出當前的日期信息
                  System.out.println("今天是"+now.getYear()+""+now.getMonth()+""+now.getDate()+"日("+now.getDateInf()+")");
                  
          //輸出三天后的日期信息
                  DateInf date=new DateInf(3);
                  System.out.println(
          "三天后是"+date.getYear()+""+date.getMonth()+""+date.getDate()+"日("+date.getDateInf()+")");
              }

          }



          posted on 2007-04-20 17:05 我為J狂 閱讀(852) 評論(1)  編輯  收藏 所屬分類: Java算法

          評論

          # re: 一個用來獲得日期信息的實用類 2007-04-20 20:49 久城

          題外話,今天上課時,感覺Excel的日期計算挺不錯。而且,在我身邊用JAVA連接Excel表的應用也有很多。可以研究下...  回復  更多評論   

          <2007年4月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          導航

          統(tǒng)計

          常用鏈接

          留言簿(11)

          隨筆分類(48)

          文章分類(29)

          常去逛逛

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 安陆市| 永善县| 凯里市| 汤原县| 商都县| 区。| 克什克腾旗| 济宁市| 克山县| 临清市| 来安县| 乌恰县| 阿合奇县| 宿迁市| 双牌县| 凤台县| 桃源县| 上饶市| 邯郸县| 朝阳市| 阜新市| 浑源县| 南溪县| 尤溪县| 张家口市| 布尔津县| 石渠县| 辽宁省| 灌南县| 乐东| 泗洪县| 崇阳县| 合阳县| 洪洞县| 安乡县| 连州市| 元谋县| 泽库县| 高雄县| 闻喜县| 宣武区|