Lena My Love

Program,Game,Eat,Sleep......

 

java中日期加减计算

        .NET里面日期的相关计算真是太简单了,直接有方法,java咋就这么麻烦呢!

public static void main(String[] args) {
        String strNow = "20060821010101";                 //当前日期 yyyyMMddhhmmss格式
        String strAddDays = "-100";                              //求前100天的日期

        Date dt = new Date(strNow .subString(0,4) + "/"
                    + strNow .subString(4,6) + "/"
                    + strNow .subString(6,8) + " "
                   + strNow .subString(8,10) + ":"
                   + strNow .subString(10,12) + ":"
                   + strNow .subString(12,14) );

     long now = dt.getTime();
     long next = now + Long.parselong(strAddDays) * 24 * 3600 * 1000;    //一天24小时*3600秒*1000毫秒
    
     Date dtNext = new Date(next);

    SimpleDateFormat df = new SimpleDateFormat("yyyyMMddhhmmss");
    String strNext = df.format(dtNext);
}

有没有人有更方便的方法?

posted on 2006-08-21 11:52  gigikouyi  阅读(3943)  评论(3编辑  收藏  举报

导航