Java Day Add addDate(String date, SimpleDateFormat format, int dayCnt)

Here you can find the source of addDate(String date, SimpleDateFormat format, int dayCnt)

Description

add Date

License

Open Source License

Declaration

public static String addDate(String date, SimpleDateFormat format, int dayCnt) 

Method Source Code


//package com.java2s;
/*//  ww  w  . ja  v a  2 s .  c om
 * @(#)DateUtils.java
 *
 * Copyright 2007 NHN Corp. All rights Reserved. 
 * NHN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static final int TIMESTAMP_FOR_A_DAY = 1000 * 60 * 60 * 24;

    public static String addDate(String date, SimpleDateFormat format, int dayCnt) {
        Date oldDate = new Date();
        long curTimeStamp = 0;

        try {
            oldDate = format.parse(date);
        } catch (ParseException e) {
            return date;
        }

        curTimeStamp = oldDate.getTime();
        curTimeStamp = curTimeStamp + (TIMESTAMP_FOR_A_DAY * dayCnt);

        String result = "";
        try {
            result = format.format(new Date(curTimeStamp));
        } catch (Exception e) {
            return date;
        }

        return result;
    }
}

Related

  1. add(int date, int days)
  2. add(String date, int day)
  3. addDate(Date d, long day)
  4. addDate(Date date, int day)
  5. addDate(java.util.Date date, int day)
  6. addDate(String str, int field, int dayNum)
  7. addDay(Date d, int amount)
  8. addDay(Date date, int day)
  9. addDay(Date date, int day)