在Java中,如何将"Wed,05 Jun 2013 00:48:12 GMT"解析为Date对象,然后以相同的格式打印日期对象.
我试过这个:
String dStr= "Wed, 05 Jun 2013 00:48:12 GMT";
SimpleDateFormat ft = new SimpleDateFormat ("E, dd MMM yyyy hh:mm:ss ZZZ");
Date t = ft.parse(dStr);
System.out.println(t);
System.out.println(ft.format(t));
Run Code Online (Sandbox Code Playgroud)
结果是
Wed Jun 05 10:48:12 EST 2013
Wed, 05 Jun 2013 10:48:12 +1000
Run Code Online (Sandbox Code Playgroud)
提前致谢:
这解决了你的问题:
import java.text.*;
import java.util.*;
public class DateIt{
public static void main(String [] args) throws Exception{
String dStr= "Wed, 05 Jun 2013 00:48:12 GMT";
SimpleDateFormat ft = new SimpleDateFormat ("E, dd MMM yyyy HH:mm:ss z");
Date t = ft.parse(dStr);
TimeZone gmt = TimeZone.getTimeZone("England/London");
ft.setTimeZone(gmt);
System.out.println(t);
System.out.println(ft.format(t));
}
}
Run Code Online (Sandbox Code Playgroud)