@Test public void test() { Demo d = new Demo() { @Override public long getCurrentTimestamp() { Calendar c = Calendar.getInstance(); c.set(2020, 1, 14); System.out.println(System.currentTimeMillis()); System.out.println(c.getTimeInMillis()); return c.getTimeInMillis(); } }; Calendar calendar = Calendar.getInstance(); calendar.set(2020, 1, 1); Date dueTime = calendar.getTime(); long days = d.calculateDelayDays(dueTime); assertEquals(days, 13L); }
public long calculateDelayDays(Date dueTime) { long currentTimestamp = getCurrentTimestamp(); if (dueTime.getTime() >= currentTimestamp) { return 0; } long delayTime = currentTimestamp - dueTime.getTime(); long delayDays = delayTime / (24 * 3600 * 1000L); return delayDays; }
Demo { public long calculateDelayDays(Date dueTime) { long currentTimestamp = getCurrentTimestamp(); if (dueTime.getTime() >= currentTimestamp) { return 0; } long delayTime = currentTimestamp - dueTime.getTime(); long delayDays = delayTime / (24 * 3600 * 1000L); return delayDays; } }
Demo { public long calculateDelayDays(Date dueTime) { long currentTimestamp = getCurrentTimestamp(); if (dueTime.getTime() >= currentTimestamp) { return 0; } long delayTime = currentTimestamp - dueTime.getTime(); long delayDays = delayTime / (24 * 3600 * 1000L); return delayDays; }  }
Demo { public long calculateDelayDays(Date dueTime) { long currentTimestamp = getCurrentTimestamp(); if (dueTime.getTime() >= currentTimestamp) { return 0; } long delayTime = currentTimestamp - dueTime.getTime(); long delayDays = delayTime / (24 * 3600 * 1000L); return delayDays; }  long calculateDelayDays(Date dueTime); long getCurrentTimestamp(); }
Demo { public long calculateDelayDays(Date dueTime) { long currentTimestamp = getCurrentTimestamp(); if (dueTime.getTime() >= currentTimestamp) { return 0; } long delayTime = currentTimestamp - dueTime.getTime(); long delayDays = delayTime / (24 * 3600 * 1000L); return delayDays; }  long calculateDelayDays(Date dueTime); long getCurrentTimestamp();  }