MsDosDateTimeUtils { public static int packTime(long time) { Calendar c = Calendar.getInstance(); c.setTime(new Date(time)); int seconds = c.get(Calendar.SECOND); int minutes = c.get(Calendar.MINUTE); int hours = c.get(Calendar.HOUR_OF_DAY); return (hours << 11) | (minutes << 5) | (seconds / 2); } private  MsDosDateTimeUtils(); static int packTime(long time); static int packCurrentTime(); static int packDate(long time); static int packCurrentDate();  }
@Test public void packTime() throws Exception { Calendar c = Calendar.getInstance(); c.set(Calendar.HOUR_OF_DAY, 8); c.set(Calendar.MINUTE, 45); c.set(Calendar.SECOND, 20); long time = c.getTime().getTime(); int packed = MsDosDateTimeUtils.packTime(time); int expectedTimeBits = 0x45AA; assertEquals(expectedTimeBits, packed); }