Android Date Interval Get dayOffset(Date date, int offset)

Here you can find the source of dayOffset(Date date, int offset)

Description

day Offset

License

Open Source License

Declaration

public static Date dayOffset(Date date, int offset) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Main {
    public static Date dayOffset(Date date, int offset) {
        return offsetDate(date, Calendar.DATE, offset);
    }//from w  w  w.jav  a 2s  .c  om

    public static Date offsetDate(Date date, int field, int offset) {
        Calendar calendar = convert(date);
        calendar.add(field, offset);
        return calendar.getTime();
    }

    private static Calendar convert(Date date) {
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        return calendar;
    }
}

Related

  1. calculateDiffInMilliSeconds(Date date1, Date date2)
  2. calculateDiffInMinutes(Date date1, Date date2)
  3. dateDiff(String startTime, String endTime)
  4. dateDiff(String startTime, String endTime, String format, String str)
  5. dayDiff(Date date1, Date date2)
  6. daysBetweenDate(Date date1, Date date2)
  7. getDiff(String startTime, String endTime)
  8. getDiff(String startTime, String endTime)
  9. getDiffDays(String startDate, String endDate)