Java Date Offset getOffsetDate(String startTime, int field, int offset)

Here you can find the source of getOffsetDate(String startTime, int field, int offset)

Description

get Offset Date

License

Apache License

Declaration

public static String getOffsetDate(String startTime, int field, int offset) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    public static String getOffsetDate(String startTime, int field, int offset) {
        try {//  w w  w  .  ja  v a 2 s  . co  m
            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) {
            e.printStackTrace();
        }
        return null;
    }
}

Related

  1. getOffsetDate(Date protoDate, int dayOffset)
  2. getOffsetDate(String strDate, int offset, String pFormat)
  3. getOffsetDate(String strDate, int offset, String pFormat)
  4. getOffsetDateInFormat(int offsetDay, String pattern)
  5. getOffsetDateToDate(Date pDate, int offset)