1
/**
2
* 取得服務器當前的各種具體時間
3
* 回車:日期時間
4
*/
5
6
import java.util.*;
7
8
public class GetNowDate{
9
Calendar calendar = null;
10
11
public GetNowDate(){
12
calendar = Calendar.getInstance();
13
calendar.setTime(new Date());
14
}
15
16
public int getYear(){
17
return calendar.get(Calendar.YEAR);
18
}
19
20
public int getMonth(){
21
return 1 + calendar.get(Calendar.MONTH);
22
}
23
24
public int getDay(){
25
return calendar.get(Calendar.DAY_OF_MONTH);
26
}
27
28
public int getHour(){
29
return calendar.get(Calendar.HOUR_OF_DAY);
30
}
31
32
public int getMinute(){
33
return calendar.get(Calendar.MINUTE);
34
}
35
36
public int getSecond(){
37
return calendar.get(Calendar.SECOND);
38
}
39
40
public String getDate(){
41
return getMonth()+"/"+getDay()+"/"+getYear();
42
}
43
44
public String getTime(){
45
return getHour()+":"+getMinute()+":"+getSecond();
46
}
47
48
public String getDate2(){
49
String yyyy="0000", mm="00", dd="00";
50
yyyy = yyyy + getYear();
51
mm = mm + getMonth();
52
dd = dd + getDay();
53
yyyy = yyyy.substring(yyyy.length()-4);
54
mm = mm.substring(mm.length()-2);
55
dd = dd.substring(dd.length()-2);
56
return yyyy + "/" + mm + "/" + dd;
57
}
58
59
public String getTime2(){
60
String hh="00", mm="00", ss="00";
61
hh = hh + getHour();
62
mm = mm + getMinute();
63
ss = ss + getSecond();
64
hh = hh.substring(hh.length()-2, hh.length());
65
mm = mm.substring(mm.length()-2, mm.length());
66
ss = ss.substring(ss.length()-2, ss.length());
67
return hh + ":" + mm + ":" + ss;
68
}
69
}

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

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69
