Java Day Add addOneDay(String strDate)

Here you can find the source of addOneDay(String strDate)

Description

add One Day

License

Open Source License

Declaration

public static String addOneDay(String strDate) 

Method Source Code

//package com.java2s;

import java.text.SimpleDateFormat;
import java.util.*;

public class Main {
    public static final String _DEFAULT1 = "yyyy-MM-dd HH:mm";
    public static final String _DEFAULT4 = "yyyy-MM-dd";

    public static String addOneDay(String strDate) { // YYYY-MM-DD
        int[] standardDays = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
        int[] leapyearDays = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
        int y = Integer.parseInt(strDate.substring(0, 4));
        int m = Integer.parseInt(strDate.substring(4, 6));
        int d = Integer.parseInt(strDate.substring(6, 8)) + 1;
        int maxDateCount = 0;
        System.out.println(y);/*from   w  ww  .  j  av a  2  s .  com*/
        System.out.println(m);
        System.out.println(d);
        if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0) {
            maxDateCount = leapyearDays[m - 1];
        } else {
            maxDateCount = standardDays[m - 1];
        }
        if (d > maxDateCount) {
            d = 1;
            m++;
        }
        if (m > 12) {
            m = 1;
            y++;
        }
        java.text.DecimalFormat yf = new java.text.DecimalFormat("0000");
        java.text.DecimalFormat mdf = new java.text.DecimalFormat("00");
        return yf.format(y) + mdf.format(m) + mdf.format(d);
    }

    public static String format(Date date) {
        return formatDate(date, _DEFAULT4);
    }

    public static String formatDate(Date date) {
        return formatDate(date, _DEFAULT1);
    }

    public static String formatDate(Date date, String style) {
        return new SimpleDateFormat(style).format(date);
    }
}

Related

  1. addDaysToDate(Date date, int value)
  2. addDaysToDate(final Date d, final int days)
  3. addDaysToDate(String s, int day, String format)
  4. addDayString5(Date date, int day)
  5. addDayToString(String strDate, int days)
  6. addOneDayForamt(String date, String format, Integer addDate)
  7. AddUtilDate(String strDate, int iDays)
  8. getAddDay(int day)
  9. getFutrueDate(Date oldDate, int addDay)