Java Date Offset getOffsetDate(Date protoDate, int dayOffset)

Here you can find the source of getOffsetDate(Date protoDate, int dayOffset)

Description

get Offset Date

License

Open Source License

Parameter

Parameter Description
protoDate a parameter
dayOffset a parameter

Declaration

public static Date getOffsetDate(Date protoDate, int dayOffset) 

Method Source Code


//package com.java2s;

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

public class Main {
    /**/*from ww  w  .  j  a  v a2 s. com*/
     * 
     * @param protoDate
     * @param dayOffset
     * @return
     */
    public static Date getOffsetDate(Date protoDate, int dayOffset) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(protoDate);
        cal.add(Calendar.DATE, -dayOffset);
        return cal.getTime();
    }

    public static String getTime(String pattern) {
        return new SimpleDateFormat(pattern).format(new Date());
    }
}

Related

  1. getOffsetDate(String startTime, int field, int offset)
  2. getOffsetDate(String strDate, int offset, String pFormat)
  3. getOffsetDate(String strDate, int offset, String pFormat)
  4. getOffsetDateInFormat(int offsetDay, String pattern)