Android Date to Calendar Convert getCalendarFromDate(Date date)

Here you can find the source of getCalendarFromDate(Date date)

Description

Get Calendar instance based on given Date object.

Parameter

Parameter Description
date - Date object.

Exception

Parameter Description
NullPointerException if any of the parameters is null.

Return

-parsed object.

Declaration

public static Calendar getCalendarFromDate(Date date) 

Method Source Code

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

public class Main{
    /**//from  w ww  .  j  ava  2  s  .c o m
     * Get {@link Calendar} instance based on given {@link Date} object.  
     * @param date -{@link Date} object.
     * @return -parsed {@link Calendar} object.
     * @throws NullPointerException if any of the parameters is null.
     */
    public static Calendar getCalendarFromDate(Date date) {
        if (StringUtils.isNull(date)) {
            throw new NullPointerException("date cannot be null");
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar;
    }
}

Related

  1. Date2Calendar(Date d)
  2. getCalendar(Date date)
  3. getCalendar(Date day)
  4. toCalendar(Date date)
  5. getCalendar(Date date)
  6. calendarFromDate(Date d)
  7. calendarDate(Date date)
  8. convert(Date date)
  9. getCalendarField(Date date, int field)