2011-10-06 83 views
0

我收到此字符串在我的SimpleDateFormat「太陽,2011年10月2日14:00:00 +0100」,可能會減少我的輸出1小時? GMT而不是+0100?TimeZone配置

感謝

+0

你想改變實際時間(即時間=時間 - 1小時),或者你只想打印時間GMT時間嗎? – Marcel

+0

你能教我兩種方法嗎?謝謝 – unpix

回答

1

以一小時關閉:

SimpleDateFormat sf = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss z", Locale.ENGLISH); 
sf.setCalendar(Calendar.getInstance(TimeZone.getTimeZone("GMT"))); 
Calendar calendar = Calendar.getInstance(); 
Date now = calendar.getTime(); 

calendar.add(Calendar.HOUR,-1); 
Date earlierTime = calendar.getTime(); 
System.out.println(sf.format(now)); // output: Thu, 06 Oct 2011 11:53:58 GMT 
System.out.println(sf.format(earlierTime)); // output: Thu, 06 Oct 2011 10:53:58 GMT 
+0

謝謝,這就是我想要的! 真的非常感謝!玩的開心! – unpix