Android Date Get getDateOffset(String date, int offset)

Here you can find the source of getDateOffset(String date, int offset)

Description

get Date Offset

Declaration

public static String getDateOffset(String date, int offset) 

Method Source Code

//package com.java2s;

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

public class Main {
    public static String getDateOffset(String date, int offset) {

        // Date tempDate = getDateObj(date, "[/]");
        Date tempDate = null;/*from ww w .  j a  va2  s  . co m*/
        if (date.indexOf("/") > 0)
            tempDate = getDateObj(date, "[/]");
        if (date.indexOf("-") > 0)
            tempDate = getDateObj(date, "[-]");
        tempDate = getDateAdd(tempDate, offset);
        return getFormatDateTime(tempDate, "yyyy/MM/dd");
    }

    public static Date getDateObj(int year, int month, int day) {
        Calendar c = new GregorianCalendar();
        c.set(year, month - 1, day);
        return c.getTime();
    }

    public static Date getDateObj(String argsDate, String split) {
        String[] temp = argsDate.split(split);
        int year = Integer.valueOf(temp[0]);
        int month = Integer.valueOf(temp[1]);
        int day = Integer.valueOf(temp[2]);
        return getDateObj(year, month, day);
    }

    public static Date getDateObj() {
        Calendar c = new GregorianCalendar();
        return c.getTime();
    }

    public static Date getDateAdd(Date date, int amount) {
        Calendar cal = new GregorianCalendar();
        cal.setTime(date);
        cal.add(GregorianCalendar.DATE, amount);
        return cal.getTime();
    }

    public static String getFormatDateTime(Date date, String format) {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.format(date);
    }
}

Related

  1. getDate(int year, int month, int date, int hourOfDay, int minute, int second)
  2. getDateFromString(String dateStr, String pattern)
  3. getDateObj()
  4. getDateObj(String argsDate, String split)
  5. getDateObj(int year, int month, int day)
  6. getDateTomorrow(String date)
  7. getDayOfWeek(Date date)
  8. getDayOfWeek(String date)
  9. getDayOfWeek(String year, String month, String day)