模拟试题

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

2011计算机二级JAVA编程:获取GMT8时间

来源:fjzsksw.com 2010-11-4 14:13:52

 

 

  获取GMT8时间

  /**

  * Description: 获取GMT8时间

  * @return 将当前时间转换为GMT8时区后的Date

  */

  public static Date getGMT8Time(){

  Date gmt8 = null;

  try {

  Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+8"),Locale.CHINESE); Calendar day = Calendar.getInstance();

  day.set(Calendar.YEAR, cal.get(Calendar.YEAR));

  day.set(Calendar.MONTH, cal.get(Calendar.MONTH));

  day.set(Calendar.DATE, cal.get(Calendar.DATE));

  day.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY));

  day.set(Calendar.MINUTE, cal.get(Calendar.MINUTE));

  day.set(Calendar.SECOND, cal.get(Calendar.SECOND));

  gmt8 = day.getTime();

  } catch (Exception e) {

  System.out.println("获取GMT8时间 getGMT8Time() error !");

  e.printStackTrace();

  gmt8 = null;

  }

  return gmt8;

  }

 

 

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