Révision 3002
tmp/org.txm.utils/src/org/txm/utils/TimeFormatter.java (revision 3002) | ||
---|---|---|
1 |
package org.txm.utils; |
|
2 |
|
|
3 |
public class TimeFormatter { |
|
4 |
public static String formatTime(String time) { |
|
5 |
try { |
|
6 |
return formatTime(Float.parseFloat(time)); |
|
7 |
} catch (Exception e) { |
|
8 |
try { |
|
9 |
return formatTime(Integer.parseInt(time)); |
|
10 |
} catch (Exception e2) { |
|
11 |
return formatTime(0.0f); |
|
12 |
} |
|
13 |
} |
|
14 |
} |
|
15 |
|
|
16 |
/** |
|
17 |
* |
|
18 |
* @param secondes |
|
19 |
* number of seconde |
|
20 |
* @return |
|
21 |
*/ |
|
22 |
public static String formatTime(int secondes) { |
|
23 |
String rez = " "; |
|
24 |
float h = secondes / 3600; |
|
25 |
secondes = secondes % 3600; |
|
26 |
float min = (secondes % 3600) / 60; |
|
27 |
int sec = secondes % 60; |
|
28 |
if (min < 10) |
|
29 |
rez = "" + (int) h + ":0" + (int) min;// +":"+time%60; |
|
30 |
else |
|
31 |
rez = "" + (int) h + ":" + (int) min;// +":"+time%60; |
|
32 |
|
|
33 |
if (sec >= 10) |
|
34 |
rez += ":" + sec; |
|
35 |
else |
|
36 |
rez += ":0" + sec; |
|
37 |
|
|
38 |
return rez; |
|
39 |
} |
|
40 |
|
|
41 |
/** |
|
42 |
* |
|
43 |
* @param time |
|
44 |
* 0.00s |
|
45 |
* @return |
|
46 |
*/ |
|
47 |
public static String formatTime(float time) { |
|
48 |
String rez = " "; |
|
49 |
float h = time / 3600; |
|
50 |
time = time % 3600; |
|
51 |
float min = (time % 3600) / 60; |
|
52 |
int sec = (int) time % 60; |
|
53 |
if (min < 10) |
|
54 |
rez = "" + (int) h + ":0" + (int) min;// +":"+time%60; |
|
55 |
else |
|
56 |
rez = "" + (int) h + ":" + (int) min;// +":"+time%60; |
|
57 |
|
|
58 |
if (sec >= 10) |
|
59 |
rez += ":" + sec; |
|
60 |
else |
|
61 |
rez += ":0" + sec; |
|
62 |
|
|
63 |
return rez; |
|
64 |
} |
|
65 |
|
|
66 |
/** |
|
67 |
* |
|
68 |
* @param time |
|
69 |
* 0.00s |
|
70 |
* @return |
|
71 |
*/ |
|
72 |
public static String formatTime(double time) { |
|
73 |
String rez = " "; |
|
74 |
double h = time / 3600; |
|
75 |
time = time % 3600; |
|
76 |
double min = (time % 3600) / 60; |
|
77 |
int sec = (int) time % 60; |
|
78 |
if (min < 10) |
|
79 |
rez = "" + (int) h + ":0" + (int) min;// +":"+time%60; |
|
80 |
else |
|
81 |
rez = "" + (int) h + ":" + (int) min;// +":"+time%60; |
|
82 |
|
|
83 |
if (sec >= 10) |
|
84 |
rez += ":" + sec; |
|
85 |
else |
|
86 |
rez += ":0" + sec; |
|
87 |
|
|
88 |
return rez; |
|
89 |
} |
|
90 |
} |
|
0 | 91 |
Formats disponibles : Unified diff