Last active
September 9, 2020 09:13
-
-
Save vipulshah2010/3c6b64bc73749d904ac62134c517f64e to your computer and use it in GitHub Desktop.
Time difference
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
boolean isValid(Date date1, Date date2) { | |
Timestamp timestamp1 = new Timestamp(date1.getTime()); | |
Timestamp timestamp2 = new Timestamp(date2.getTime()); | |
long milliseconds = timestamp2.getTime() - timestamp1.getTime(); | |
int seconds = (int) milliseconds / 1000; | |
int hours = seconds / 3600; | |
int minutes = (seconds % 3600) / 60; | |
seconds = (seconds % 3600) % 60; | |
System.out.println("timestamp1: " + timestamp1); | |
System.out.println("timestamp2: " + timestamp2); | |
System.out.println("Difference: "); | |
System.out.println(" Hours: " + hours); | |
System.out.println(" Minutes: " + minutes); | |
System.out.println(" Seconds: " + seconds); | |
return hours < 24; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment