【问题标题】:parsing date object with jodatime not working用jodatime解析日期对象不起作用
【发布时间】:2015-12-09 20:57:38
【问题描述】:

当我尝试解析格式为 1950-01-01T00:00:00 的 Date 对象时,日期时间将得到昨天。

我也尝试使用DateTimeZone.getDefault() 获取时区,但它仍然无法正常工作。 我可以使用哪个时区来修复它?

DateTime dateTime = new DateTime(1950-01-01T00:00:00, DateTimeZone.UTC);

output:
dateTime.getDayOfMonth() = 31
dateTime.getMonthOfYear() = 12
dateTime.getYear() = 1949

你能帮帮我吗?

谢谢。

【问题讨论】:

    标签: android datetime jodatime


    【解决方案1】:

    通过在应用程序类中添加以下代码修复

    DateTimeZone.setDefault(DateTimeZone.forID("Europe/Istanbul"));

    【讨论】:

    • DateTime dateTime = new DateTime(1950-01-01T00:00:00, DateTimeZone.forID("Europe/Istanbul")); 会更好,以避免操纵默认时区(可能手机上的用户想要每个标准的另一个,或者其他应用程序或应用程序的其他部分不会受到影响这样的变化)。
    • @Meno 那是本地应用程序 :)
    猜你喜欢
    • 2018-02-23
    • 2016-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多