fork download
  1. import java.sql.Timestamp;
  2.  
  3. class Main {
  4. private static long MintueToMillis(int m) {
  5. return m * 60000;
  6. }
  7.  
  8. // DBからとってくる値
  9. private static int getIntervalMin() {
  10. return 5;
  11. }
  12.  
  13. public static boolean isStoppable(Timestamp ts1, Timestamp ts2) {
  14. long diff = ts2.getTime() - ts1.getTime();
  15. return !(diff >= 0 && diff <= MintueToMillis(getIntervalMin()));
  16. }
  17.  
  18. public static void main(String args[]) {
  19. Timestamp now = new Timestamp(System.currentTimeMillis());
  20. Timestamp next1 = new Timestamp(now.getTime() + MintueToMillis(1)); // 1分後
  21. Timestamp next2 = new Timestamp(now.getTime() + MintueToMillis(6)); // 6分後
  22.  
  23. System.out.println("now: " + now.toString());
  24. System.out.println(next1.toString() + " -> stoppable: " + isStoppable(now, next1));
  25. System.out.println(next2.toString() + " -> stoppable: " + isStoppable(now, next2));
  26. }
  27. }
Success #stdin #stdout 0.11s 212864KB
stdin
Standard input is empty
stdout
now: 2012-03-18 09:09:19.319
2012-03-18 09:10:19.319 -> stoppable: false
2012-03-18 09:15:19.319 -> stoppable: true