Java Utililty Methods Date to Calendar

List of utility methods to do Date to Calendar

Description

The list of methods to do Date to Calendar are organized into topic(s).

Method

CalendarDateToCalendar(Date date)
Date To Calendar
Calendar cal = Calendar.getInstance();
cal.setTime(date);
return cal;
GregorianCalendardateToGregorianCalendar(Date date)
date To Gregorian Calendar
if (date == null)
    return null;
GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT+09:00"), Locale.KOREAN);
cal.setTime(date);
return cal;
CalendargetCalendar(boolean dateAndTime)
get Calendar
Calendar cal = Calendar.getInstance();
cal.set(2010, 1, 1, 0, 0, 0);
cal.set(Calendar.MILLISECOND, 0); 
if (!dateAndTime) {
    return cal;
} else {
    cal.set(Calendar.HOUR_OF_DAY, 10);
    cal.set(Calendar.MINUTE, 20);
...
CalendargetCalendar(Date date)
get Calendar
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar;
CalendargetCalendar(final Date date, final boolean stripTime)
get Calendar
final Calendar c = Calendar.getInstance();
c.setTime(date);
if (stripTime) {
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
return c;
CalendargetCalendar(String dateString)
get Calendar
Calendar calendar = Calendar.getInstance();
String[] items = dateString.split("[-| |:]");
int len = items.length;
if (len == 1) {
    String item = items[0];
    if (item.length() >= 4) {
        calendar.set(Calendar.YEAR, Integer.parseInt(item.substring(0, 4)));
    if (item.length() >= 6) {
        calendar.set(Calendar.MONTH, Integer.parseInt(item.substring(4, 6)) - 1);
    if (item.length() >= 8) {
        calendar.set(Calendar.DATE, Integer.parseInt(item.substring(6, 8)));
    if (item.length() >= 10) {
        calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(item.substring(8, 10)));
    if (item.length() >= 12) {
        calendar.set(Calendar.MINUTE, Integer.parseInt(item.substring(10, 12)));
    if (item.length() >= 14) {
        calendar.set(Calendar.SECOND, Integer.parseInt(item.substring(12, 14)));
} else {
    if (len > 1) {
        calendar.set(Calendar.MONTH, Integer.parseInt(items[1]) - 1);
    } else {
        calendar.set(Calendar.MONTH, 0);
    if (len > 2) {
        calendar.set(Calendar.DATE, Integer.parseInt(items[2]));
    } else {
        calendar.set(Calendar.DATE, 1);
    if (len > 3) {
        calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(items[3]));
    } else {
        calendar.set(Calendar.HOUR_OF_DAY, 0);
    if (len > 4) {
        calendar.set(Calendar.MINUTE, Integer.parseInt(items[4]));
    } else {
        calendar.set(Calendar.MINUTE, 0);
    if (len > 5) {
        calendar.set(Calendar.SECOND, Integer.parseInt(items[5]));
    } else {
        calendar.set(Calendar.SECOND, 0);
return calendar;
CalendarnewCalendar(Date date)
new Calendar
Calendar calendar = new GregorianCalendar();
calendar.setTime(date);
return calendar;
CalendartoCalendar(Date date)
Convert the given date to a Calendar object.
Calendar calendar = Calendar.getInstance();
calendar.clear();
calendar.setTime(date);
return calendar;
CalendartoCalendar(Date date)
Converts a java.util.Date to a java.util.Calendar.
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar;
CalendartoCalendar(Date date)
to Calendar
return toCalendar(date, null, null);