2016-07-14 01:46:44 +02:00
|
|
|
package fr.pandacube.java.util.measurement;
|
2016-02-16 20:07:51 +01:00
|
|
|
|
|
|
|
public class TimeUtil {
|
|
|
|
public static String durationToString (long msec_time, boolean dec_seconde)
|
|
|
|
{
|
|
|
|
int j = 0, h = 0, m = 0, s = 0;
|
|
|
|
long msec = msec_time;
|
|
|
|
|
|
|
|
j = (int) (msec / (1000 * 60 * 60 * 24));
|
2016-05-26 11:49:45 +02:00
|
|
|
msec -= (long)(1000 * 60 * 60 * 24) * j;
|
2016-02-16 20:07:51 +01:00
|
|
|
h = (int) (msec / (1000 * 60 * 60));
|
2016-05-26 11:49:45 +02:00
|
|
|
msec -= (long)(1000 * 60 * 60) * h;
|
2016-02-16 20:07:51 +01:00
|
|
|
m = (int) (msec / (1000 * 60));
|
2016-05-26 11:49:45 +02:00
|
|
|
msec -= (long)(1000 * 60) * m;
|
2016-02-16 20:07:51 +01:00
|
|
|
s = (int) (msec / 1000);
|
2016-05-26 11:49:45 +02:00
|
|
|
msec -= (long)1000 * s;
|
2016-02-16 20:07:51 +01:00
|
|
|
|
|
|
|
String result = "";
|
|
|
|
if (j>0) result = result.concat(j+"j ");
|
|
|
|
if (h>0) result = result.concat(h+"h ");
|
|
|
|
if (m>0) result = result.concat(m+"m ");
|
|
|
|
if (s>0 && !dec_seconde) result = result.concat(s+"s");
|
|
|
|
else if (dec_seconde && (s>0 || msec > 0))
|
|
|
|
{
|
|
|
|
msec += s*1000;
|
|
|
|
result = result.concat((msec/1000D)+"s");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result.equals(""))
|
|
|
|
result = "0";
|
|
|
|
|
|
|
|
return result.trim();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String durationToString (long msec_time)
|
|
|
|
{
|
|
|
|
return durationToString(msec_time, false);
|
|
|
|
}
|
2016-05-26 11:49:45 +02:00
|
|
|
|
|
|
|
|
2016-02-16 20:07:51 +01:00
|
|
|
}
|