Java Date to Calendar toCalendar(Date date)

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

Description

to Calendar

License

MIT License

Declaration

public static Calendar toCalendar(Date date) 

Method Source Code

//package com.java2s;
/*!//  ww w  .j  a v  a  2 s.c  o  m
 * mifmi-commons4j
 * https://github.com/mifmi/mifmi-commons4j
 *
 * Copyright (c) 2015 mifmi.org and other contributors
 * Released under the MIT license
 * https://opensource.org/licenses/MIT
 */

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

import java.util.Locale;

import java.util.TimeZone;

public class Main {
    public static Calendar toCalendar(Date date) {
        return toCalendar(date, null, null);
    }

    public static Calendar toCalendar(Date date, TimeZone timeZone, Locale locale) {
        if (date == null) {
            return null;
        }
        return toCalendar(date.getTime(), timeZone, locale);
    }

    public static Calendar toCalendar(long date) {
        return toCalendar(date, null, null);
    }

    public static Calendar toCalendar(long date, TimeZone timeZone, Locale locale) {
        Calendar cal = getCalendar(timeZone, locale);
        cal.setTimeInMillis(date);
        return cal;
    }

    public static Calendar getCalendar(TimeZone timeZone, Locale locale) {
        Calendar cal;
        if (timeZone == null) {
            if (locale == null) {
                cal = Calendar.getInstance();
            } else {
                cal = Calendar.getInstance(locale);
            }
        } else {
            if (locale == null) {
                cal = Calendar.getInstance(timeZone);
            } else {
                cal = Calendar.getInstance(timeZone, locale);
            }
        }
        return cal;
    }
}

Related

  1. getCalendar(final Date date, final boolean stripTime)
  2. getCalendar(String dateString)
  3. newCalendar(Date date)
  4. toCalendar(Date date)
  5. toCalendar(Date date)
  6. toCalendar(Date date)
  7. toCalendar(Date date)
  8. toCalendar(Date dtime)
  9. toCalendar(Date value)