Java Utililty Methods Day of

List of utility methods to do Day of

Description

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

Method

DateparseFromDays(String date)
Parses a string of the following format to a Date :

yyyy-MM-dd

return parse(getFormatToDays(), date);
DateplusDay(Date date, int day)
plus Day
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.DATE, day);
return cal.getTime();
DateplusDays(Date date, int days)
plus Days
if (date == null)
    date = getToday();
return changeDays(date, days);
DatesetDays(Date date, int amount)
Sets the day of month field to a date returning a new object.
return set(date, Calendar.DAY_OF_MONTH, amount);
StringstartOfDay(Date date, String format)
start Of Day
SimpleDateFormat sdf = new SimpleDateFormat(format);
return sdf.format(startOfDay(date));
StringstringSomeDaysAgo(Date currentTime, int days)
string Some Days Ago
if (currentTime == null)
    return "";
Calendar cal = Calendar.getInstance();
cal.setTime(currentTime);
cal.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH) - days);
return convertDate2String5(cal.getTime());
DatestrToShortday(String s)
str To Shortday
try {
    SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-dd");
    ParsePosition parseposition = new ParsePosition(0);
    return simpledateformat.parse(s, parseposition);
} catch (Exception e) {
    return null;
DatesubtractDate(Date d, long day)
subtract Date
long time = d.getTime();
day = day * 24 * 60 * 60 * 1000;
time -= day;
return new Date(time);
StringtoCurrentDatedefer(int day)
to Current Datedefer
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime(new Date());
calendar.add(GregorianCalendar.DAY_OF_MONTH, day);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
return format.format(calendar.getTime());
StringToEnglishDay(Date dt)
To English Day
if (dt == null)
    return "";
DateFormatSymbols sym = new DateFormatSymbols();
sym.setMonths(MONTHS);
SimpleDateFormat f = new SimpleDateFormat("dd MMM, yyyy", sym);
return f.format(dt);