2015-08-14 65 views
1
String strDateTime = "2015-08-14 16:25:12"; //From database that was stored in UTC 
DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss").withZone(DateTimeZone.UTC);  
DateTime dateTime = DateTime.parse(strDateTime, dateTimeFormatter); 
LocalDateTime local = dateTime.toLocalDateTime(); 
// local = 2015-08-14T16:25:12.000 

I want to get the date in my local time zone??? 
where local = 2015-08-14T11:25:12.000 // 11 VS 16 

任何想法我在这里做错了吗?这种使用ISO日期时间格式如何解析UTC时间并显示JodaTime java中的本地时间?

回答

3

在乔达,一个LocalDateTime不是日期时间你现在所在,这是没有任何时区信息的日期时间。从the docs

LocalDateTime是一个不可修改的日期时间类,它表示没有时区的日期时间。

通过询问dateTime.toLocalDateTime(),您只是要求与原始UTC版本相同的DateTime,但将UTC信息剥离。相反,它听起来像你想在时区之间转换; LocalDateTime可能对您或您的解决方案没有用处。

使用DateTime.toDateTime(DateTimeZone)在时区之间进行转换;您可以使用DateTimeZone.getDefault来获取系统的默认时区,这可能是您要查找的内容。