2008年5月13日 星期二

使用java.util.TimeZone 取得各時區的時間


所謂的UTC時間就是指表示自從標準基準時間,即1970年1月1日00:00:00 GMT)以來的指定毫秒數,所以這個時間所有計算都是一樣的。

利用 java.util.TimeZone 可以幫助我們取得各時區的時間,
一個sample code:

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm");
TimeZone timeZoneParis = TimeZone.getTimeZone("Asia/Taipei");
Locale localeEN = Locale.US;
Date curDate = new Date();
dateFormat.setTimeZone(timeZoneParis);
System.out.println(dateFormat.format(curDate));

要取得各時區的iD 可以用以下的method
timezone.getAvailableIDs();

沒有留言: