Here you can find the source of getOffsetDate(String startTime, int field, int offset)
public static String getOffsetDate(String startTime, int field, int offset)
//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; } }