MsDosDateTimeUtils { public static int packDate(long time) { Calendar c = Calendar.getInstance(); c.setTime(new Date(time)); int day = c.get(Calendar.DAY_OF_MONTH); int month = c.get(Calendar.MONTH) + 1; int year = c.get(Calendar.YEAR) - 1980; Verify.verify(year >= 0 && year < 128); return (year << 9) | (month << 5) | day; } private  MsDosDateTimeUtils(); static int packTime(long time); static int packCurrentTime(); static int packDate(long time); static int packCurrentDate();  }
@Test public void packDate() throws Exception { Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR, 2016); c.set(Calendar.MONTH, 0); c.set(Calendar.DAY_OF_MONTH, 5); long time = c.getTime().getTime(); int packed = MsDosDateTimeUtils.packDate(time); int expectedDateBits = 0x4825; assertEquals(expectedDateBits, packed); }