[ Back | Previous | Next ]

How to clone/copy a Gregorian Calendar?

Package:
java.util.*
Product:
JDK
Release:
1.1.x
Related Links:
Calendar
EventObject
Hashtable
Locale
Properties
PropertyResourceBundle
TimeZone
Comment:
/**
 * This method was created in VisualAge.
 * @return java.util.GregorianCalendar
 * @param tmp java.util.GregorianCalendar
 */
public static java.util.GregorianCalendar copyCalendar(java.util.GregorianCalendar tmp) {
	GregorianCalendar newCalendar = new GregorianCalendar(new Locale(Locale.ENGLISH.getISO3Language(), Locale.GERMAN.getISO3Country()));
	newCalendar.set(Calendar.HOUR_OF_DAY, tmp.get(Calendar.HOUR_OF_DAY));
	newCalendar.set(Calendar.YEAR, tmp.get(Calendar.YEAR));
	newCalendar.set(Calendar.MONTH, tmp.get(Calendar.MONTH));
	newCalendar.set(Calendar.DAY_OF_MONTH, tmp.get(Calendar.DAY_OF_MONTH));
	newCalendar.set(Calendar.MINUTE, tmp.get(Calendar.MINUTE));
	newCalendar.set(Calendar.SECOND,0);
	newCalendar.set(Calendar.MILLISECOND,0); 
	return newCalendar;
}
1