Java格式化日期時間格式
今天寫了一個格式化日期時間格式的程序,在這里記錄一下,同時也方便需要的人使用。程序代碼如下:
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
}
這里程序的輸出結(jié)果為:2008年10月07日 14時26分27秒 
2

3

4 /**
5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

posted on 2008-10-07 14:28 wzhongyu 閱讀(2200) 評論(0) 編輯 收藏 所屬分類: Java學習