Android Calendar Get getCurrentDateByOffset(String format, int calendarField, int offset)

Here you can find the source of getCurrentDateByOffset(String format, int calendarField, int offset)

Description

get Current Date By Offset

Declaration

public static String getCurrentDateByOffset(String format,
        int calendarField, int offset) 

Method Source Code

//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;

    }
}

Related

  1. getYear()
  2. getYear(Calendar c)
  3. extractDateFromCalendarTime(Calendar time)
  4. extractTimeFromCalendarTime(Calendar time)
  5. getCurrentCalendar()
  6. getCalenderFromDateString(String dateString)