獲得指定時(shí)區(qū)的格式化日期字符串
Posted on 2008-02-07 07:04 云自無心水自閑 閱讀(1569) 評(píng)論(0) 編輯 收藏 所屬分類: Java 、心得體會(huì)




















其中timeZoneOffset就是時(shí)區(qū),比如東八區(qū),就傳入8,西二區(qū)就傳入-2
新的方法,使用指定的TimeZone ID來獲得TimeZone,這樣更精確,因?yàn)橛幸恍┏鞘校m然時(shí)區(qū)。比如:悉尼和布里斯班,都是東10區(qū),但是悉尼實(shí)行夏令時(shí),所以夏天的時(shí)候,悉尼要比布里斯班早1小時(shí)。TimeZone timeZoneSYD = TimeZone.getTimeZone("Australia/Sydney");
TimeZone timeZoneBNE = TimeZone.getTimeZone("Australia/Brisbane");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdf.setTimeZone(timeZoneSYD);
Date date = new Date();
System.out.println(sdf.format(date));
sdf.setTimeZone(timeZoneBNE);
System.out.println(sdf.format(date));
其中TimeZone的ID列表,可以使用函數(shù)
public static String[] TimeZone.getAvailableIDs();
來獲得