/** * Create a Time object for storing a time with the time set to the specified time of the Java Date * object. */ public Time(final Date date) { final Calendar localTime = createCalendar(); // localTime.setTimeZone(TimeZone.getDefault()); localTime.setTimeZone(UtcTimeZone); localTime.setTime(date); this.date = time(localTime.get(Calendar.HOUR_OF_DAY), localTime.get(Calendar.MINUTE)); }
private Date time(final int hour, final int minute) { checkTime(hour, minute, 0); final Calendar cal = createCalendar(); cal.setTimeZone(UtcTimeZone); cal.set(Calendar.HOUR_OF_DAY, hour); cal.set(Calendar.MINUTE, minute); cal.set(Calendar.MILLISECOND, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.MONTH, 0); cal.set(Calendar.YEAR, 1970); return cal.getTime(); }
/** * Create a Time object set to the current time. */ public Time() { final Calendar cal = createCalendar(); cal.setTimeZone(TimeZone.getDefault()); cal.setTime(new Date(Clock.getTime())); date = time(cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE)); }