Java Day getDayRange(String bday, String eday)

Here you can find the source of getDayRange(String bday, String eday)

Description

get Day Range

License

Apache License

Declaration

public static String[] getDayRange(String bday, String eday) 

Method Source Code

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

import java.text.SimpleDateFormat;
import java.util.ArrayList;

import java.util.Calendar;

import java.util.GregorianCalendar;

public class Main {

    public static String[] getDayRange(String bday, String eday) {
        GregorianCalendar rightNow = new GregorianCalendar(Integer.parseInt(bday.substring(0, 4)),
                Integer.parseInt(bday.substring(4, 6)) - 1, Integer.parseInt(bday.substring(6, 8)));
        int i = 0;
        String s = null;//from  w w  w. ja  v a2 s . com
        ArrayList al = new ArrayList();
        al.add(bday);
        while (true) {
            i++;
            rightNow.add(Calendar.DAY_OF_YEAR, 1);
            s = getDefaultDateFormat().format(rightNow.getTime());
            al.add(s);
            if (s.equals(eday))
                break;

        }

        return (String[]) al.toArray(new String[0]);
    }

    public static int parseInt(String s) {
        return Integer.parseInt(isZero(s));
    }

    public static SimpleDateFormat getDefaultDateFormat() {
        return new SimpleDateFormat("yyyyMMdd");
    }

    public static String[] toArray(String s) {
        return toArray(s, ",");
    }

    public static String[] toArray(String s, String delim) {
        if (isNull(s))
            return new String[0];
        return s.split(delim);
    }

    public static String isZero(String o) {
        return (o == null || o.toString().trim().equals("")) ? "0" : o;
    }

    public static boolean isNull(Object s) {
        if (s == null || s.toString().trim().length() == 0 || s.equals("null"))
            return true;
        else
            return false;
    }
}

Related

  1. getDayNumber()
  2. getDayOfDate(Date date)
  3. getDayOffset(String date, int offset, String format)
  4. getDayofTheDate(Date d1)
  5. getDAYOFWEEK(String strDate)
  6. getDays(Date day, int preDays, String format)
  7. getDays(Date sd, Date ed)
  8. getDays(String yyyy)
  9. getDaysAgo(int interval)