Java Calendar Time copyLocalTime(final Calendar from, final Calendar to)

Here you can find the source of copyLocalTime(final Calendar from, final Calendar to)

Description

Copy the local time from one calendar to another.

License

Open Source License

Parameter

Parameter Description
from the source calendar, e.g. 23/12/2011 11:55:33.066 GMT-12.
to the destination calendar, e.g. 01/01/2000 0:00 GMT+13.

Return

the modified destination calendar, e.g. 23/12/2011 11:55:33.066 GMT+13.

Declaration

public final static Calendar copyLocalTime(final Calendar from, final Calendar to) 

Method Source Code

//package com.java2s;
/*/*from  w  w  w.  j  a  va 2s  .  c  o m*/
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 * 
 * Copyright 2008 jOpenDocument, by ILM Informatique. All rights reserved.
 * 
 * The contents of this file are subject to the terms of the GNU
 * General Public License Version 3 only ("GPL").  
 * You may not use this file except in compliance with the License. 
 * You can obtain a copy of the License at http://www.gnu.org/licenses/gpl-3.0.html
 * See the License for the specific language governing permissions and limitations under the License.
 * 
 * When distributing the software, include this License Header Notice in each file.
 * 
 */

import java.util.Calendar;

public class Main {
    /**
     * Copy the local time from one calendar to another. Except if both calendars have the same time
     * zone, from.getTimeInMillis() will be different from to.getTimeInMillis().
     * 
     * @param from the source calendar, e.g. 23/12/2011 11:55:33.066 GMT-12.
     * @param to the destination calendar, e.g. 01/01/2000 0:00 GMT+13.
     * @return the modified destination calendar, e.g. 23/12/2011 11:55:33.066 GMT+13.
     */
    public final static Calendar copyLocalTime(final Calendar from, final Calendar to) {
        to.clear();
        for (final int field : new int[] { Calendar.YEAR, Calendar.DAY_OF_YEAR, Calendar.HOUR_OF_DAY,
                Calendar.MINUTE, Calendar.SECOND, Calendar.MILLISECOND }) {
            to.set(field, from.get(field));
        }
        return to;
    }
}

Related

  1. convertToActiveDirectoryTime(Calendar calendar)
  2. convertToCalendar(long adTimeValue)
  3. convertToTimeStpam(Calendar cal)
  4. convertToTimeZone(Calendar time, TimeZone timeZone)
  5. copyLocalTime(final Calendar from, final Calendar to)
  6. currentTimeAsCalendar()
  7. dateTimeToFMDateTime(Calendar dateTime)
  8. elapsedTime(Calendar before, Calendar after)
  9. equalizeTime(final Calendar toEqualize, final Calendar source)