-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTImeDemo.java
More file actions
40 lines (36 loc) · 1.1 KB
/
TImeDemo.java
File metadata and controls
40 lines (36 loc) · 1.1 KB
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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javabasic;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
*
* @author nhatc
*/
public class TImeDemo {
public static void main(String[] args) {
//get time by millisecond
long start = System.currentTimeMillis();
try {
for (int i = 0; i < 100; i++) {
Thread.sleep(3);
}
} catch (Exception e) {
}
long end = System.currentTimeMillis();
System.out.println("Millies: " + (end - start));
//get time by nanosecond
start = System.nanoTime();
end = System.nanoTime();
System.out.println("Nano: " + (end - start));
//display the system time
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH.mm.ss");
Date date = new Date();
String day = dateFormat.format(date);
System.out.println(day);
}
}