Solved Getting distance in seconds between two dates.

Discussion in 'Spigot Plugin Development' started by Acquaticallen_, Feb 3, 2020.

Thread Status:
Not open for further replies.
  1. I'm trying to find a way to get the distance (in seconds) between two dates, the point is that i only have a method to convert seconds in date format, so like 350 seconds, 5 minutes and 50 seconds.

    my problem is that i can't find out a method to get distance in seconds between two dates, what i'm trying is to find the distance between the current date time (that can get by formatting currentTimeMillis) and 00:00 AM (of course of the next day)
     
  2. md_5

    Administrator Developer

    Code (Text):

                    Calendar tomorrow = Calendar.getInstance();
                    tomorrow.add( Calendar.DATE, 1 );
                    tomorrow.set( tomorrow.get( Calendar.YEAR ), tomorrow.get( Calendar.MONTH ), tomorrow.get( Calendar.DATE ), 0, 0, 0 );

                    Calendar now = Calendar.getInstance();

                    long difference = ( tomorrow.getTimeInMillis() - now.getTimeInMillis() ) / 1000L;
     
     
    • Useful Useful x 2
Thread Status:
Not open for further replies.