forked from JustinSDK/JavaSE6Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDateTimeInstanceDemo.java
More file actions
37 lines (33 loc) · 1.26 KB
/
DateTimeInstanceDemo.java
File metadata and controls
37 lines (33 loc) · 1.26 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
package onlyfun.caterpillar;
import java.text.DateFormat;
import java.util.Date;
public class DateTimeInstanceDemo {
public static void main(String[] args) {
// 取得目前時間
Date date = new Date();
// 簡短資訊格式
DateFormat shortFormat =
DateFormat.getDateTimeInstance(
DateFormat.SHORT, DateFormat.SHORT);
// 中等資訊格式
DateFormat mediumFormat =
DateFormat.getDateTimeInstance(
DateFormat.MEDIUM, DateFormat.MEDIUM);
// 長資訊格式
DateFormat longFormat =
DateFormat.getDateTimeInstance(
DateFormat.LONG, DateFormat.LONG);
// 詳細資訊格式
DateFormat fullFormat =
DateFormat.getDateTimeInstance(
DateFormat.FULL, DateFormat.FULL);
System.out.println("簡短資訊格式:" +
shortFormat.format(date));
System.out.println("中等資訊格式:" +
mediumFormat.format(date));
System.out.println("長資訊格式:" +
longFormat.format(date));
System.out.println("詳細資訊格式:" +
fullFormat.format(date));
}
}