Java Utililty Methods Day

List of utility methods to do Day

Description

The list of methods to do Day are organized into topic(s).

Method

StringgetDayOffset(String date, int offset, String format)
get Day Offset
Calendar calendar = Calendar.getInstance(Locale.CHINA);
calendar.setTime(toDate(date));
calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) + offset);
SimpleDateFormat sdf = new SimpleDateFormat(format);
return sdf.format(calendar.getTime());
StringgetDayofTheDate(Date d1)
To Find the day of the week
String day = null;
DateFormat f = new SimpleDateFormat("EEE");
try {
    day = f.format(d1);
} catch (Exception e) {
    e.printStackTrace();
return day;
...
StringgetDAYOFWEEK(String strDate)
Regresa el dia de la semana, dada la fecha DOMINGO, LUNES, MARTES, MIERCOLES, JUEVES, VIERNES, SABADO
String dia = null;
Calendar calendar = Calendar.getInstance();
calendar.setTime(convertStringToDate(strDate));
switch (calendar.get(Calendar.DAY_OF_WEEK)) {
case Calendar.SUNDAY:
    dia = "DOMINGO";
    break;
case Calendar.MONDAY:
...
String[]getDayRange(String bday, String eday)
get Day Range
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;
ArrayList al = new ArrayList();
al.add(bday);
while (true) {
    i++;
...
ListgetDays(Date day, int preDays, String format)
get Days
List<String> returnValue = new ArrayList<String>();
SimpleDateFormat sdf = new SimpleDateFormat(format);
Calendar c = Calendar.getInstance();
c.setTime(day);
for (int i = 0; i < preDays; i++) {
    c.add(Calendar.DAY_OF_YEAR, -1);
    returnValue.add(new String(sdf.format(c.getTime())));
return returnValue;
intgetDays(Date sd, Date ed)
get Days
return (int) ((ed.getTime() - sd.getTime()) / (3600 * 24 * 1000));
String[]getDays(String yyyy)
get Days
StringBuilder sb = new StringBuilder();
long starttime = stringToTime("yyyyMMdd", yyyy + "0101").getTime();
long lasttime = stringToTime("yyyyMMdd", yyyy + "1231").getTime();
for (; starttime <= lasttime; starttime += 1000 * 3600 * 24) {
    sb.append(timeToString("yyyyMMdd", new Date(starttime)));
    sb.append(':');
return sb.toString().split(":");
...
StringgetDaysAgo(int interval)
get Days Ago
Date date = new Date();
long time = date.getTime() / 1000L - (interval * 60 * 60 * 24);
date.setTime(time * 1000L);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try {
    return format.format(date);
} catch (Exception ex) {
    System.out.println(ex.getMessage());
...
ListgetDaysByYearMonth(String ym)
get Days By Year Month
List<String> list = new ArrayList<String>();
int maxDate = getMaxDayByYearMonth(ym);
for (int i = 1; i <= maxDate; i++) {
    String d = String.valueOf(i < 10 ? "0" + i : i);
    list.add(ym + "-" + d);
return list;
intgetDaysForDate(String date)
get Days For Date
Date curDate = strToDate(date);
Calendar calendar = Calendar.getInstance();
calendar.setTime(curDate);
return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);