Bonjour,

j'ai 2 dates et heures dont je voudrais calculer la différence en minutes :
les dates sont au format String JJ/MM/AAAA, et les heures au format String HHhMM

voici mon code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
private String getDuree(String d1, String h1, String d2, String h2) {
 
        GregorianCalendar t1 = new GregorianCalendar(Integer.parseInt(d1.substring(6)),
                                                     Integer.parseInt(d1.substring(3, 5)),
                                                     Integer.parseInt(d1.substring(0, 2)),
                                                     Integer.parseInt(h1.substring(0, 2)),
                                                     Integer.parseInt(h1.substring(3)));
        GregorianCalendar t2 = new GregorianCalendar(Integer.parseInt(d2.substring(6)),
                                                     Integer.parseInt(d2.substring(3, 5)),
                                                     Integer.parseInt(d2.substring(0, 2)),
                                                     Integer.parseInt(h2.substring(0, 2)),
                                                     Integer.parseInt(h2.substring(3)));
        long aTime = t1.getTimeInMillis();
        long bTime = t2.getTimeInMillis();
        long minutes = (bTime - aTime) / 60000;
...
Ca marche dans tous les cas, sauf lorsqu'on est à cheval sur 2 mois :
exemple :
d1=30/06/2008 - h1=20h42
d2=01/07/2008 - h2=02h54
résultat : 1812 minutes (au lieu de 372)
Si on change de jour en restant dans le même mois, c'est correct :
d1=29/06/2008 - h1=19h35
d2=30/06/2008 - h2=01h47
résultat : 372 minutes

Qu'est ce qui cloche ?

Merci,

Nico