java,php,asp.net,linux,javascript,mysql,mssql,oracle,编程

取得服务器当前的各种具体时间

转载请注明:http://www.pmjava.com/Article/ShowInfo.asp?ID=56580
import java.util.*;

public class GetNowDate{
    Calendar  calendar
= null;
 
   
public GetNowDate(){
        calendar
= Calendar.getInstance();
        calendar.setTime(
new Date());
    }
 
   
public int getYear(){
       
return calendar.get(Calendar.YEAR);
    }
 
   
public int getMonth(){
       
return 1 + calendar.get(Calendar.MONTH);
    }
 
   
public int getDay(){
       
return calendar.get(Calendar.DAY_OF_MONTH); } public int getHour(){
       
return calendar.get(Calendar.HOUR_OF_DAY); } public int getMinute(){
       
return calendar.get(Calendar.MINUTE);
    }
 
   
public int getSecond(){
       
return calendar.get(Calendar.SECOND);
    }
   
   
public String getDate(){
       
return getMonth()+"/"+getDay()+"/"+getYear();
    }
 
   
public String getTime(){
       
return getHour()+":"+getMinute()+":"+getSecond();
    }
 
   
public String getDate2(){
        String yyyy
="0000", mm="00", dd="00";
        yyyy
= yyyy + getYear();
        mm  
= mm   + getMonth();
        dd  
= dd + getDay();
        yyyy
= yyyy.substring(yyyy.length()-4);
        mm  
= mm.substring(mm.length()-2);
        dd  
= dd.substring(dd.length()-2);
       
return yyyy + "/" + mm + "/" +  dd;
    }
 
   
public String getTime2(){
        String hh
="00", mm="00", ss="00";
        hh
= hh + getHour();
        mm
= mm + getMinute();
        ss
= ss + getSecond();
        hh
= hh.substring(hh.length()-2, hh.length());
        mm
= mm.substring(mm.length()-2, mm.length());
        ss
= ss.substring(ss.length()-2, ss.length());
       
return hh + ":" + mm + ":" + ss;
    }
}
                                                                  

posted on 2009-06-10 21:24 rrong_m 阅读(146) 评论(0)  编辑  收藏

<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

导航

统计

常用链接

随笔档案

文章分类

文章档案

java编程

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜