Java Utililty Methods Date Offset

List of utility methods to do Date Offset

  1. HOME
  2. Java
  3. D
  4. Date Offset

Description

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

Method

String getOffsetDateInFormat(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());
Date getOffsetDate(Date protoDate, int dayOffset)
get Offset Date
Calendar cal = Calendar.getInstance();
cal.setTime(protoDate);
cal.add(Calendar.DATE, -dayOffset);
return cal.getTime();
String getOffsetDate(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) {
...
Date getOffsetDateToDate(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;
int getOffsetMins(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);
String getOffsetDate(String strDate, int offset, String pFormat)
get Offset Date
SimpleDateFormat fmt = new SimpleDateFormat(pFormat);
Date date = fmt.parse(strDate);
return getOffsetDate(date, offset, pFormat);
String getOffsetMonth(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) {
...
String getOffsetDate(String strDate, int offset, String pFormat)
get Offset Date
SimpleDateFormat fmt = new SimpleDateFormat(pFormat);
Date date = fmt.parse(strDate);
return getOffsetDate(date, offset, pFormat);


AltStyle によって変換されたページ (->オリジナル) /