How do you set the time and only the time in a calendar in Java?

pupeno picture pupeno · Jan 20, 2009 · Viewed 55k times · Source

Having the hours and minutes, is there any easier or better way to set it into a Calendar object than:

calendar.set(calendar.get(Calendar.YEAR),
                        calendar.get(Calendar.MONTH),
                        calendar.get(Calendar.DAY_OF_MONTH),
                        hour, minute);

Answer

Xn0vv3r picture Xn0vv3r · Jan 20, 2009

From here:

calendar.set(Calendar.HOUR_OF_DAY, hour);
calendar.set(Calendar.MINUTE, minute);