一個(gè)用來(lái)獲得日期信息的實(shí)用類

          /*
           *@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;

              
          // 得到當(dāng)前日期
              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();
                  
          //輸出當(dāng)前的日期信息
                  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) 評(píng)論(1)  編輯  收藏 所屬分類: Java算法

          評(píng)論

          # re: 一個(gè)用來(lái)獲得日期信息的實(shí)用類 2007-04-20 20:49 久城

          題外話,今天上課時(shí),感覺(jué)Excel的日期計(jì)算挺不錯(cuò)。而且,在我身邊用JAVA連接Excel表的應(yīng)用也有很多。可以研究下...  回復(fù)  更多評(píng)論   

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

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(11)

          隨筆分類(48)

          文章分類(29)

          常去逛逛

          搜索

          積分與排名

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 安西县| 从化市| 孝昌县| 中卫市| 浪卡子县| 喜德县| 峨眉山市| 晋城| 温州市| 金川县| 葵青区| 寿阳县| 东光县| 广宗县| 台安县| 望都县| 合作市| 库车县| 清涧县| 从化市| 四子王旗| 积石山| 仙桃市| 满洲里市| 左权县| 益阳市| 巴林右旗| 金阳县| 淮阳县| 玉树县| 大田县| 钟祥市| 尼勒克县| 四子王旗| 罗甸县| 新闻| 全南县| 郯城县| 凤山县| 甘洛县| 鹿邑县|