Java Calendar Create getCalendarFromDates(Date date, Date hourMinuteMillisseconds)

Here you can find the source of getCalendarFromDates(Date date, Date hourMinuteMillisseconds)

Description

Merge two Date variables to compose a single Calendar object.

License

Open Source License

Parameter

Parameter Description
date Date object containing the date - doesn't matter hour, minute, second and millisseconds values.
hourMinuteMillisseconds Date object containing hour, minute, second and millisseconds. Doesn't matter date values.

Return

a Calendar object

Declaration

public static final Calendar getCalendarFromDates(Date date, Date hourMinuteMillisseconds) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    /**//w  w  w  .  ja v  a2  s .c om
     * Merge two Date variables to compose a single Calendar object.
     * 
     * @param date
     *            Date object containing the date - doesn't matter hour, minute,
     *            second and millisseconds values.
     * @param hourMinuteMillisseconds
     *            Date object containing hour, minute, second and millisseconds.
     *            Doesn't matter date values.
     * @return a Calendar object
     */
    public static final Calendar getCalendarFromDates(Date date, Date hourMinuteMillisseconds) {
        Calendar ret = Calendar.getInstance();
        ret.setTime(date);

        Calendar hour = Calendar.getInstance();
        hour.setTime(hourMinuteMillisseconds);

        ret.set(Calendar.HOUR_OF_DAY, hour.get(Calendar.HOUR_OF_DAY));
        ret.set(Calendar.MINUTE, hour.get(Calendar.MINUTE));
        ret.set(Calendar.SECOND, hour.get(Calendar.SECOND));
        ret.set(Calendar.MILLISECOND, hour.get(Calendar.MILLISECOND));

        return ret;
    }
}

Related

  1. getCalendarFieldName(int field)
  2. getCalendarFormYear(int year)
  3. getCalendarForNextRun( GregorianCalendar startTime, int targetDay, int targetHour)
  4. getCalendarForSchedule(Calendar cal)
  5. getCalendarForTime(final long timeInMilliseconds)
  6. getCalendarFromSystemTimeInMillis(long date)
  7. getCalendarGMT()
  8. getCalendarInstance()
  9. getCalendarInstance()