Java Calendar Time equalizeTime(final Calendar toEqualize, final Calendar source)

Here you can find the source of equalizeTime(final Calendar toEqualize, final Calendar source)

Description

sets the time of the day of the first argument, so that it is equal to the time of the day of the second argument.

License

Open Source License

Parameter

Parameter Description
toEqualize a Calendar, whose time will be equalized to the source's time of the day
source the time of the day of this Calendar is taken.

Return

a new Calendar object, with the date equal to toEqualize, but the time of the date is equal to that of the source Calendar.

Declaration

public static Calendar equalizeTime(final Calendar toEqualize, final Calendar source) 

Method Source Code

//package com.java2s;
/*//  w w w.j a  v a  2 s . c o  m
This file is part of Cyclos (www.cyclos.org).
A project of the Social Trade Organisation (www.socialtrade.org).
    
Cyclos is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
    
Cyclos is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with Cyclos; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    
 */

import java.util.Calendar;

public class Main {
    /**
     * sets the time of the day of the first argument, so that it is equal to the time of the day of the second argument.
     * @param toEqualize a Calendar, whose time will be equalized to the source's time of the day
     * @param source the time of the day of this Calendar is taken.
     * @return a new Calendar object, with the date equal to toEqualize, but the time of the date is equal to that of the source Calendar.
     */
    public static Calendar equalizeTime(final Calendar toEqualize, final Calendar source) {
        if (source == null) {
            return null;
        }
        final int hourOfDay = source.get(Calendar.HOUR_OF_DAY);
        final int minute = source.get(Calendar.MINUTE);
        final int second = source.get(Calendar.SECOND);
        final int milliSecond = source.get(Calendar.MILLISECOND);
        final Calendar result = (Calendar) toEqualize.clone();
        result.set(Calendar.HOUR_OF_DAY, hourOfDay);
        result.set(Calendar.MINUTE, minute);
        result.set(Calendar.SECOND, second);
        result.set(Calendar.MILLISECOND, milliSecond);
        return result;
    }
}

Related

  1. copyLocalTime(final Calendar from, final Calendar to)
  2. copyLocalTime(final Calendar from, final Calendar to)
  3. currentTimeAsCalendar()
  4. dateTimeToFMDateTime(Calendar dateTime)
  5. elapsedTime(Calendar before, Calendar after)
  6. equalsIgnoreTimeZone(final Calendar c1, final Calendar c2)
  7. getCalendarWithoutTimeZone(Date date)
  8. getClientCurrentDate(final Calendar calendar, final TimeZone timeZone)
  9. getCurrentTimeDecimal(Calendar cal)