模拟试题

3773考试网计算机等级考试模拟试题正文

2011计算机二级JAVA编程:取得服务器当前的各种具体时间

来源:fjzsksw.com 2010-11-4 14:21:16

 

 

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

  /**

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

  * 回车:日期时间

  */

  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;

  }

  }

 

 

触屏版 电脑版
3773考试网 琼ICP备12003406号-1