-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimeUtil.java
45 lines (33 loc) · 1.07 KB
/
TimeUtil.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package javaToolkit.lib.utils;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import org.eclipse.jdt.core.dom.ThisExpression;
public class TimeUtil {
public long startTime;
public long endTime;
public TimeUtil() {
this.startTime = System.nanoTime();
}
public void setEndTime() {
this.endTime = System.nanoTime();
}
public int computeTimeCostInMinuts() {
return (int) ((this.endTime - this.startTime) / (1_000_000_000 * 60));
}
public int computeTimeCostInSecond() {
return (int) ((this.endTime - this.startTime) / 1_000_000_000);
}
public static void printCurTime() {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
LocalDateTime now = LocalDateTime.now();
System.out.println(dtf.format(now));
}
public static void printCurTimewithMsg(String msg) {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
LocalDateTime now = LocalDateTime.now();
System.out.println(msg + "\t" + dtf.format(now));
}
public static void main(String[] args) {
printCurTimewithMsg("test");
}
}