Java Day of getSpcilNumDayArray(Date startDate, int num)

Here you can find the source of getSpcilNumDayArray(Date startDate, int num)

Description

get Spcil Num Day Array

License

Apache License

Declaration

public static Date[] getSpcilNumDayArray(Date startDate, int num) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Main {
    public static final String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
    public static final String DATE_PATTERN = "yyyy-MM-dd";

    public static Date[] getSpcilNumDayArray(Date startDate, int num) {
        Date[] dates = new Date[2];
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {/*from  ww w .  j a va 2  s.  co m*/
            dates[0] = sdf.parse(format(startDate, "yyyy-MM-dd"));
            Calendar calendar = new GregorianCalendar();
            calendar.setTime(dates[0]);
            calendar.add(Calendar.DATE, num);
            calendar.add(Calendar.SECOND, -1);
            dates[1] = calendar.getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return dates;
    }

    public static Date parse(String str, String formatPattern) {
        try {
            return new SimpleDateFormat(formatPattern).parse(str);
        } catch (ParseException e) {
            throw new RuntimeException("could not parse date: " + str + " LEGACY_FORMAT = "
                    + new SimpleDateFormat(formatPattern).toPattern(), e);
        }
    }

    public static Date parse(String str) {
        if (str.length() != DATE_PATTERN.length() && str.length() != DATE_TIME_PATTERN.length()) {
            return null;
        }
        String formatPattern = DATE_PATTERN;
        if (str.length() > 10) {
            formatPattern = DATE_TIME_PATTERN;
        }

        try {
            return new SimpleDateFormat(formatPattern).parse(str);
        } catch (ParseException e) {
            throw new RuntimeException("could not parse date: " + str + " LEGACY_FORMAT = "
                    + new SimpleDateFormat(formatPattern).toPattern(), e);
        }
    }

    public static String format(Date date, String formatPattern) {
        // Assert.notNull(date);
        return new SimpleDateFormat(formatPattern).format(date);
    }
}

Related

  1. getPaxBirthday()
  2. getPriorDay(int offset, String pattern)
  3. getRunningTime(Date date, SimpleDateFormat sday, String line)
  4. getSetDate(Date dt, int dayNum)
  5. getSignContinusDay(Date lastSignTime)
  6. getSpecifiedDayAfter(String specifiedDay)
  7. getSpecifiedDayAfter(String specifiedDay, int afterDay)
  8. getSpecifiedDayTimeAfter(Date date)
  9. getStandardDayFormat(Date day)