Last active
December 18, 2015 10:39
-
-
Save regispires/5769950 to your computer and use it in GitHub Desktop.
Exemplo de uso de diferença entre duas datas usando nossas classes.
O resultado da execução é mostrado a seguir.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
public static void main(String[] args) { | |
try { | |
Date d1 = DateUtils.parse("08:00", "HH:mm"); | |
Date d2 = DateUtils.parse("12:01", "HH:mm"); | |
// Obtem diferença em minutos | |
long totalMinutos = DateUtils.diff(d1, d2, DateUtils.HOUR_OF_DAY, DateUtils.MINUTE); | |
System.out.println("Total de minutos: " + totalMinutos); | |
// Transforma minutos para o formato "HH:mm" | |
System.out.println("Total de horas no formato HH:mm: " + DateUtils.minutes2Hours(totalMinutos)); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
... | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Total de minutos: 241 | |
Total de horas no formato HH:mm: 04:01 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment