fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.text.SimpleDateFormat;
  5. public class Main
  6. {
  7. public static void main(String[] args) {
  8. SimpleDateFormat sf = new SimpleDateFormat("dd-MM-yy HH:mm");
  9. Date currentTimeandDate = new Date(System.currentTimeMillis());
  10. String dbTiming = "15-2-21 11:34";
  11. String currentTiming = sf.format(currentTimeandDate);
  12.  
  13. try{
  14. Date date1 = sf.parse(dbTiming);
  15. Date date2 = sf.parse(currentTiming);
  16. System.out.println("date1: " + date1);
  17. System.out.println("date2: " + date2);
  18. boolean isBefore = date1.before(date2);
  19. // int val = date1.compareTo(date2);
  20. System.out.println(isBefore +" "+ currentTiming);
  21.  
  22. }catch(Exception e){
  23.  
  24. }
  25. }
  26. }
Success #stdin #stdout 0.3s 40368KB
stdin
Standard input is empty
stdout
date1: Mon Feb 15 11:34:00 GMT 2021
date2: Tue Feb 16 07:17:00 GMT 2021
true 16-02-21 07:17