Last active
October 30, 2015 02:45
-
-
Save victorvaz/566975e68c66b5e56c7f to your computer and use it in GitHub Desktop.
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
/** | |
* Classe para funções de tratamento de data. | |
*/ | |
public class Data | |
{ | |
/** | |
* Função para formatar o tempo em segundos para HH:MM:SS | |
* @param tempoSegundos Tempo gasto em segundos | |
* @return String Tempo formatado | |
*/ | |
public String formataTempo(long tempoSegundos) | |
{ | |
long segundos = tempoSegundos % 60; | |
tempoSegundos /= 60; | |
long minutos = tempoSegundos % 60; | |
tempoSegundos /= 60; | |
long horas = tempoSegundos % 24; | |
return strzero(horas) + ":" + strzero(minutos) + ":" + strzero(segundos); | |
} | |
/** | |
* Função para formatar com zero. | |
* @param num | |
* @return | |
*/ | |
private String strzero(long num) | |
{ | |
if (num < 10) | |
return "0" + String.valueOf(num); | |
else | |
return String.valueOf(num); | |
} | |
} |
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
// Unix time do momento que iniciou o processo: | |
long unixTimeInicio; | |
// Unix time do momento que finalizou o processo: | |
long unixTimeFim; | |
Data cData = new Data(); | |
tempoGasto = cData.formataTempo(unixTimeFim - unixTimeInicio); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment