Skip to content

Commit 23bce29

Browse files
committed
improve timeutil
1 parent 1337902 commit 23bce29

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lib/utils/TimeUtil.java

+22
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,29 @@
33
import java.time.LocalDateTime;
44
import java.time.format.DateTimeFormatter;
55

6+
import org.eclipse.jdt.core.dom.ThisExpression;
7+
68
public class TimeUtil {
79

10+
public long startTime;
11+
public long endTime;
12+
13+
public TimeUtil() {
14+
this.startTime = System.nanoTime();
15+
}
16+
17+
public void setEndTime() {
18+
this.endTime = System.nanoTime();
19+
}
20+
21+
public int computeTimeCostInMinuts() {
22+
return (int) ((this.endTime - this.startTime) / (1_000_000_000 * 60));
23+
}
24+
25+
public int computeTimeCostInSecond() {
26+
return (int) ((this.endTime - this.startTime) / 1_000_000_000);
27+
}
28+
829
public static void printCurTime() {
930
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
1031
LocalDateTime now = LocalDateTime.now();
@@ -20,4 +41,5 @@ public static void printCurTimewithMsg(String msg) {
2041
public static void main(String[] args) {
2142
printCurTimewithMsg("test");
2243
}
44+
2345
}

0 commit comments

Comments
 (0)