Here you can find the source of getCurrentDateByOffset(String format, int calendarField, int offset)
public static String getCurrentDateByOffset(String format, int calendarField, int offset)
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.GregorianCalendar; public class Main { public static String getCurrentDateByOffset(String format, int calendarField, int offset) { String mDateTime = null;//from w w w . j a v a 2 s .c om try { SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat( format); Calendar c = new GregorianCalendar(); c.add(calendarField, offset); mDateTime = mSimpleDateFormat.format(c.getTime()); } catch (Exception e) { e.printStackTrace(); } return mDateTime; } }