fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. import java.time.* ;
  8. import java.time.format.* ;
  9. import java.time.temporal.* ;
  10. import java.text.SimpleDateFormat;
  11.  
  12.  
  13. /* Name of the class has to be "Main" only if the class is public. */
  14. class Ideone
  15. {
  16. public static void main (String[] args) throws java.lang.Exception
  17. {
  18.  
  19. String attributeTimestamp = "Wed Jul 24 08:14:00 2024";
  20. String currentTimestamp = "Wed Jul 24 08:18:00 2024";
  21. //get current date in the format
  22. //Date currentDate = new Date();
  23. SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM d HH:mm:ss yyyy");
  24. //dateFormat.setTimeZone(TimeZone.getTimeZone("PST"));
  25. //String currentTimestamp = dateFormat.format(currentDate);
  26. //System.out.println( currentTimestamp + " currentTimestamp " );
  27.  
  28. Date jMXAttributeTimestamp = dateFormat.parse(attributeTimestamp);
  29. Date currentDateTimestamp = dateFormat.parse(currentTimestamp);
  30. long dateDifference = currentDateTimestamp.getTime() - jMXAttributeTimestamp.getTime();
  31.  
  32. System.out.println( dateDifference + " date Difference ");
  33.  
  34.  
  35. }
  36. }
Success #stdin #stdout 0.26s 59576KB
stdin
Standard input is empty
stdout
240000 date Difference