Exprimer une durée en terme de HH:MM:SS

Author:

Exprimer,une,durée,en,terme,de,HH:MM:SS
{filelink=5612}


import java.util.Calendar;

public class Affichage {
  public static void main(String args[])
  {
    Calendar cal1 = Calendar.getInstance();
    Calendar cal2 = Calendar.getInstance();
    cal2.add(Calendar.HOUR, 2);
    cal2.add(Calendar.MINUTE, 42);
    cal2.add(Calendar.SECOND, 12);
    long secs = (cal2.getTimeInMillis() - cal1.getTimeInMillis()) / 1000;
    String display = String.format("%02d:%02d:%02d", secs / 3600, (secs % 3600) / 60, (secs % 60));
    System.out.println(display);

  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *