Java Calendar from Date date2Calendar(Date date)

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

Description

Converts the specified Date to Calendar using the system default time zone.

License

MIT License

Parameter

Parameter Description
date a date.

Return

the calendar.

Declaration

public static Calendar date2Calendar(Date date) 

Method Source Code

//package com.java2s;
/*//from   www . j av  a  2s. c  o m
 * Copyright (c) 2015-2016 QuartzDesk.com.
 * Licensed under the MIT license (https://opensource.org/licenses/MIT).
 */

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import java.util.TimeZone;

public class Main {
    /**
     * Converts the specified {@link Date} to {@link Calendar} using the
     * system default time zone.
     *
     * @param date a date.
     * @return the calendar.
     */
    public static Calendar date2Calendar(Date date) {
        return date2Calendar(date, TimeZone.getDefault());
    }

    /**
     * Converts the specified {@link Date} to {@link Calendar} using the
     * specified time zone.
     *
     * @param date     a date.
     * @param timeZone a time zone.
     * @return the calendar.
     */
    public static Calendar date2Calendar(Date date, TimeZone timeZone) {
        if (date == null)
            return null;

        Calendar cal = new GregorianCalendar(timeZone);
        cal.setTime(date);
        return cal;
    }
}

Related

  1. convertDateToCalendar(Date date)
  2. convertDateToCalendar(Date date)
  3. convertDateToCalendar(Date date)
  4. convertDateToCalendar(final Date d, boolean lenient)
  5. convertDateToCalendar(final Date dateToCompare)
  6. date2Calendar(Date date)
  7. date2Calendar(Date date)
  8. Date2Calendar(Date inDate)
  9. dateToCalendar(Date d)