Java Day Next getNextDay(Date nowdate, int delay)

Here you can find the source of getNextDay(Date nowdate, int delay)

Description

get Next Day

License

Open Source License

Declaration

public static Date getNextDay(Date nowdate, int delay) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.ParsePosition;
import java.text.SimpleDateFormat;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Main {

    public static Date getNextDay(Date nowdate, int delay) {
        long myTime;
        Calendar calendar = new GregorianCalendar();
        for (int i = 0; i < delay; i++) {
            myTime = (nowdate.getTime() / 1000) + i * 24 * 60 * 60;
            calendar.setTimeInMillis(myTime);
            if (calendar.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY
                    && calendar.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {
                nowdate.setTime(myTime * 1000);
            }//from  w w  w . j  a v  a  2  s .  c  o  m
        }
        return nowdate;
    }

    public static String getNextDay(String nowdate, String delay) {
        try {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            String mdate = "";
            Date d = strToDate(nowdate);
            long myTime = (d.getTime() / 1000) + Integer.parseInt(delay) * 24 * 60 * 60;
            d.setTime(myTime * 1000);
            mdate = format.format(d);
            return mdate;
        } catch (Exception e) {
            return "";
        }
    }

    public static Date strToDate(String strDate) {
        return strToDate(strDate, "yyyy-MM-dd");
    }

    public static Date strToDate(String strDate, String format) {
        if (strDate == null) {
            return null;
        }
        SimpleDateFormat formatter = new SimpleDateFormat(format);
        ParsePosition pos = new ParsePosition(0);
        Date strtodate = formatter.parse(strDate, pos);
        return strtodate;
    }
}

Related

  1. getNextDay()
  2. getNextDay(Date date)
  3. getNextDay(Date date)
  4. getNextDay(String date)
  5. getNextDay(String dateStr)
  6. getNextDay(String day)
  7. getNextDay(String nowdate, String delay)