Java Calendar Calculate normalizedClone(final Calendar cal)

Here you can find the source of normalizedClone(final Calendar cal)

Description

Clones and normalizes a calendar.

License

Open Source License

Declaration

public static Calendar normalizedClone(final Calendar cal) 

Method Source Code

//package com.java2s;
/*/*from w w  w  .ja  v a  2s.  c  o m*/
 * Copyright 2011 - 2012
 * All rights reserved. License and terms according to LICENSE.txt file.
 * The LICENSE.txt file and this header must be included or referenced 
 * in each piece of code derived from this project.
 */

import java.util.*;

public class Main {
    /**
     * Clones and normalizes a calendar.
     */
    public static Calendar normalizedClone(final Calendar cal) {
        final Calendar cl = (Calendar) cal.clone();
        normalize(cl);
        return cl;
    }

    /**
     * Normalizes a date to be comparable with another date,
     * fixed at 12 hours, 0 seconds, 0 minutes of the day GMT+0.
     */
    public static void normalize(final Calendar cal) {
        cal.set(Calendar.HOUR_OF_DAY, 12);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        cal.setTimeZone(TimeZone.getTimeZone("GMT+0"));
    }
}

Related

  1. isSameInstant(Calendar cal1, Calendar cal2)
  2. isSameLocalTime(Calendar cal1, Calendar cal2)
  3. maximizeTime(Calendar cal)
  4. millisToCalendar(long millis)
  5. normalize(final Calendar cal)
  6. postpone(final Calendar calendar, final int measureUnit, final int amount)
  7. resetCalendarTime(Calendar calendar)
  8. roundBack(Calendar start)
  9. roundCalToNextQuarterHour(GregorianCalendar cal)