Mega Code Archive

 
Categories / Android / Date Type
 

Get hour different

import java.util.Date; class Common {   public long[] getHourDiff(Date entrada, Date saida) {     Long diffInSeconds = (saida.getTime() - entrada.getTime()) / 1000;     long diffResult[] = new long[] { 0, 0 };     long convertedDiffInSeconds = Long.parseLong(diffInSeconds.toString()         .replaceAll("-", ""));     diffResult[1] = (convertedDiffInSeconds = (convertedDiffInSeconds / 60)) >= 60 ? convertedDiffInSeconds % 60         : convertedDiffInSeconds;     diffResult[0] = (convertedDiffInSeconds = (convertedDiffInSeconds / 60)) >= 24 ? convertedDiffInSeconds % 24         : convertedDiffInSeconds;     return diffResult;   } }