posts - 33,  comments - 17,  trackbacks - 0
 1/**
 2 * 取得服务器当前的各种具体时间
 3 * 回车:日期时间
 4 */

 5
 6import java.util.*;
 7
 8public 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}
posted on 2008-07-23 17:34 scea2009 阅读(94) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航:
 

<2008年7月>
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

常用链接

留言簿(1)

随笔分类

随笔档案

PL/SQL存储过程与函数

搜索

  •  

最新评论

阅读排行榜

评论排行榜