Java Utililty Methods Date Offset

List of utility methods to do Date Offset

Description

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

Method

StringgetOffsetDateInFormat(int offsetDay, String pattern)
get Offset Date In Format
DateFormat dateFormat = new SimpleDateFormat(pattern);
Calendar cal = Calendar.getInstance();
if (offsetDay != 0) {
    cal.add(Calendar.DATE, offsetDay);
return dateFormat.format(cal.getTime());
DategetOffsetDate(Date protoDate, int dayOffset)
get Offset Date
Calendar cal = Calendar.getInstance();
cal.setTime(protoDate);
cal.add(Calendar.DATE, -dayOffset);
return cal.getTime();
StringgetOffsetDate(String startTime, int field, int offset)
get Offset Date
try {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(sdf.parse(startTime));
    calendar.roll(field, offset);
    String offsetTime = sdf.format(calendar.getTime());
    return offsetTime;
} catch (Exception e) {
...
DategetOffsetDateToDate(Date pDate, int offset)
get Offset Date To Date
Calendar c = Calendar.getInstance();
Date ret = null;
try {
    c.setTime(pDate);
    c.add(6, offset);
    ret = c.getTime();
} catch (Exception e) {
return ret;
intgetOffsetMins(String strDate, String strDate2)
get Offset Mins
String pFormat = "yyyy-MM-dd HH:mm";
SimpleDateFormat fmt = new SimpleDateFormat(pFormat);
SimpleDateFormat fmt2 = new SimpleDateFormat(pFormat);
Date paramDate1 = fmt.parse(strDate);
Date paramDate2 = fmt2.parse(strDate2);
return getOffsetMins(paramDate1, paramDate2);
StringgetOffsetDate(String strDate, int offset, String pFormat)
get Offset Date
SimpleDateFormat fmt = new SimpleDateFormat(pFormat);
Date date = fmt.parse(strDate);
return getOffsetDate(date, offset, pFormat);
StringgetOffsetMonth(Date pDate, int offset, String pFormat)
get Offset Month
SimpleDateFormat fmt = new SimpleDateFormat(pFormat);
Calendar c = Calendar.getInstance();
String ret = "";
try {
    c.setTime(pDate);
    c.add(Calendar.MONTH, offset);
    ret = fmt.format(c.getTime());
} catch (Exception e) {
...
StringgetOffsetDate(String strDate, int offset, String pFormat)
get Offset Date
SimpleDateFormat fmt = new SimpleDateFormat(pFormat);
Date date = fmt.parse(strDate);
return getOffsetDate(date, offset, pFormat);