-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTimeTest.java
More file actions
30 lines (27 loc) · 1.05 KB
/
Copy pathTimeTest.java
File metadata and controls
30 lines (27 loc) · 1.05 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
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class TimeTest {
public static void main(String[] args) {
// get current unixno(ms)
System.out.println(System.currentTimeMillis());
System.out.println(Calendar.getInstance().getTimeInMillis());
System.out.println(new Date().getTime());
// get current unix(s)
System.out.println(System.currentTimeMillis() / 1000);
System.out.println(Calendar.getInstance().getTimeInMillis() / 1000);
System.out.println(new Date().getTime() / 1000);
// get time
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
// out string
System.out.println(df.format(new Date()));
df.getCalendar();
// get time to unix
try {
System.out.println(new SimpleDateFormat("yyyy/MM/dd HH:mm:ss:SSS").parse("2017/11/11 11:11:11:111").getTime());
} catch (ParseException e) {
e.printStackTrace();
}
}
}