Java GMT时间 转化作本地时间

Java GMT时间 转化为本地时间

 

//GMT 字符串时间转化了本地时间。

public static void tdate3(){

  SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss 'GMT'", Locale.US);  

   sdf.setTimeZone(TimeZone.getTimeZone("GMT"));  

   Date ftime = null;

try {

ftime = sdf.parse("Thu, 14 Jun 2012 07:17:21 GMT");

} catch (ParseException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

  SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

  //sdf2.setTimeZone(TimeZone.getDefault());

   System.out.println(sdf.format(ftime));

   System.out.println(sdf2.format(ftime));

}

输出:

 

Thu, 14 Jun 2012 07:17:21 GMT

2012-06-14 15:17:21

总得来说只相差8小时

使用以上代码,相看网站网页最后修改时间

Response Hearder

HTTP/1.1 200 OK

Server: Apache-Coyote/1.1

Content-Length: 0

Date: Thu, 14 Jun 2012 07:17:21 GMT

 

从Header 中看到时间再加8小时就是北京时间.