今天写了一个格式化日期时间格式的程序,在这里记录一下,同时也方便需要的人使用。程序代码如下:
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秒