小编mat*_*oom的帖子

Joda Time给出了错误的时区

我正在使用Joda time(1.6)库并且它使用错误的时区(英国夏令时而不是GMT)继续返回DateTime对象.

我的Windows工作站(运行JDK 1.6.0_16)认为它在GMT中,如果从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"            
    }
}
Run Code Online (Sandbox Code Playgroud)

通过静态初始化程序进行调试,org.joda.time.DateTimeZone我看到System.getProperty("user.timezone")调用"Europe/London"按预期方式给出.

java jodatime

13
推荐指数
1
解决办法
1万
查看次数

标签 统计

java ×1

jodatime ×1