時區
TimeZone類
為了演示這個概念
表 C
import java
import java
import java
import java
public class DateExample
public static void main(String[] args) {
// Get the system time zone
TimeZone timeZoneFL = TimeZone
System
System
System
TimeZone timeZoneLondon = TimeZone
System
System
System
燭imeZone timeZoneParis = TimeZone
System
System
System
}
}
其輸出如下
Eastern Standard Time
RawOffset:
Uses daylight saving: true
GMT+
RawOffset:
Uses daylight saving: true
Central European Standard Time
RawOffset:
Uses daylight saving: true
正如你所看見的
國際化的時期顯示了時區轉換
讓我們來看一個結合了國際化顯示
表 D
import java
import java
import java
import java
public class DateExample
public static void main(String[] args) {
Locale localeEN = Locale
Locale localeFrance = Locale
TimeZone timeZoneMiami = TimeZone
TimeZone timeZoneParis = TimeZone
DateFormat dateFormatter = DateFormat
DateFormat
DateFormat
localeEN);
DateFormat dateFormatterParis = DateFormat
DateFormat
DateFormat
localeFrance);
Date curDate = new Date();
System
// Print the Miami time zone display name in English
System
// Set the time zone of the dateFormatter to Miami time zone
dateFormatter
// Print the formatted date
System
// Set the time zone of the date formatter to Paris time zone
dateFormatter
// Print the Paris time zone display name in English
System
// Print the Paris time in english
System
System
// Print the Miami time zone display name in French
System
// Set the timezone of the
// dateFormatterParis to Miami time zone
dateFormatterParis
// Print the formatted date in French
燬ystem
// Set the timezone of the date formatter to Paris time zone
dateFormatterParis
// Print the Paris time zone display name in French
System
// Print the Paris time in French
System
}
}
這個例子的輸出是
Display for Miami office
Eastern Standard Time
Friday
Central European Standard Time
Saturday
Display for Paris office
GMT
vendredi
GMT+
samedi
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26088.html