1
import java.text.SimpleDateFormat;
2
import java.util.Date;
3
4
/**
5
*
6
* 格式化日期
7
*
8
*/
9
public class FormatDate
10
{
11
public static String formatDate(Date date){
12
SimpleDateFormat sdf = new SimpleDateFormat("yyyy 年 MM 月 dd 日");
13
return sdf.format(date);
14
}
15
16
public static String formatTime(Date date){
17
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH時mm分ss秒");
18
return sdf.format(date);
19
}
20
21
public static void main(String[] args){
22
System.out.println(formatTime(new Date()));
23
}
24
}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

這里程序的輸出結果為:2008年10月07日 14時26分27秒