Java Day From getPlusDay(String _oneDay, int _aFewDays)

Here you can find the source of getPlusDay(String _oneDay, int _aFewDays)

Description

get Plus Day

License

Open Source License

Declaration

public static String getPlusDay(String _oneDay, int _aFewDays) 

Method Source Code


//package com.java2s;

import java.util.*;

public class Main {
    public static String getPlusDay(String _oneDay, int _aFewDays) {

        _oneDay = deleteDash(_oneDay);/*  www.ja va  2s .co m*/
        _oneDay = deleteSlash(_oneDay);

        String res;

        int year = Integer.parseInt(_oneDay.substring(0, 4));
        int month = Integer.parseInt(_oneDay.substring(4, 6));
        int day = Integer.parseInt(_oneDay.substring(6, 8));

        Calendar wCal = Calendar.getInstance();
        wCal.set(year, month - 1, day);
        wCal.add(Calendar.DATE, _aFewDays);

        year = wCal.get(Calendar.YEAR);
        month = wCal.get(Calendar.MONTH) + 1;
        day = wCal.get(Calendar.DATE);

        res = Integer.toString(year);

        if (month < 10)
            res += "0" + Integer.toString(month);
        else
            res += Integer.toString(month);

        if (day < 10)
            res += "0";

        res += Integer.toString(day);

        return toDateFormat(res);
    }

    public static String deleteDash(String value) {

        return deleteChar(value, "-");
    }

    public static String deleteSlash(String value) {
        return deleteChar(value, "/");
    }

    public static String toDateFormat(String _srcDate) {

        if (_srcDate == null || _srcDate.length() != 8)
            return _srcDate;
        return _srcDate.substring(0, 4) + "-" + _srcDate.substring(4, 6) + "-" + _srcDate.substring(6);
    }

    public static String deleteChar(String source, String deleteStr) {
        if (source == null || "".equals(source.trim())) {
            return "";
        }
        StringBuffer temp = new StringBuffer("");
        StringTokenizer st = new StringTokenizer(source, deleteStr);

        while (st.hasMoreTokens()) {
            temp.append(st.nextToken());
        }

        return temp.toString();
    }
}

Related

  1. getIntervalInDaysSofar(Date from)
  2. getLastDay(Date date)
  3. getNextDay(Date startTime, int n)
  4. getNextDay(String date)
  5. getNoonOfDay(Date day)
  6. getServerOffset(boolean useDaylightSavingTime)
  7. getTimeField(Date day, int field)
  8. isBusinessDay(int dateIntToCheck)
  9. isDefaultWorkingDay(Date date)