我使用Joda time(1.6)庫和它保持返回datetime對象與錯誤的時區,英國夏令時間,而不是GMT。約達時間給出了錯誤的時區
我的Windows工作站(運行JDK 1.6.0_16)認爲這是在格林尼治標準時間,如果我從JDK日期/時間類得到默認的時區是正確的(GMT)。我在我們的Linux服務器上也獲得了相同的行爲。我認爲這可能是Joda的時區數據庫文件中的錯誤,因此我使用最新的數據庫重建了該jar,但沒有任何更改。
import java.util.TimeZone;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.LocalTime;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.ISODateTimeFormat;
public class TimeZoneTest {
public static void main(String[] args) {
DateTimeFormatter timeParser = ISODateTimeFormat.timeParser();
TimeZone timeZone = TimeZone.getDefault();
System.out.println(timeZone.getID()); // "Europe/London"
System.out.println(timeZone.getDisplayName()); // "Greenwich Mean Time"
DateTimeZone defaultTimeZone = DateTimeZone.getDefault();
System.out.println(defaultTimeZone.getID()); //"Europe/London"
System.out.println(defaultTimeZone.getName(0L)); //"British Summer Time"
DateTime currentTime = new DateTime();
DateTimeZone currentZone = currentTime.getZone();
System.out.println(currentZone.getID()); //"Europe/London"
System.out.println(currentZone.getName(0L)); //"British Summer Time"
}
}
調試通過靜態初始化器在org.joda.time.DateTimeZone
我看到System.getProperty("user.timezone")
調用提供"Europe/London"
預期。
擴大答案提供現實問題的解釋 – jitter 2009-11-11 10:56:20