我正在添加这个问题,因为我是Java和Android的新手,我搜索了几个小时试图解决这个问题.答案来自相关答案的组合,所以我想我会记录我为其他可能正在努力的人学到的东西.见答案.
对于一些背景知识,我的经验主要是PHP的Web开发和一点Ruby.我唯一的操作系统是Linux(Ubuntu Studio),我(不情愿地)在Android Studio 2.1.2中开发我的第一个Android应用程序.我的Java设置如下:
>java -version
> openjdk version "1.8.0_91"
> OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-3ubuntu1~15.10.1-b14)
> OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)
datetime android android-gradle-plugin threetenbp threetenabp
我想以UTC格式获取当前时间.到目前为止我所做的是(仅用于测试目的):
    DateTime dt = new DateTime();
    DateTimeZone tz = DateTimeZone.getDefault();
    LocalDateTime nowLocal = new LocalDateTime();
    DateTime nowUTC = nowLocal.toDateTime(DateTimeZone.UTC);
    Date d1 = nowLocal.toDate();
    Date d2 = nowUTC.toDate();
    L.d("tz: " + tz.toString());
    L.d("local: " + d1.toString());
    L.d("utc: " + d2.toString());
d1 是我当地的时间,没关系d2 是我当地时间+ 1,但应该是当地时间 -  1 ...我的本地时区是UTC + 1(根据调试输出和列表:https://www.joda.org/joda-time/timezones.html)...
如何正确地从一个时区转换为另一个时区(包括毫秒表示)?
编辑
我需要日期/毫秒...这不是关于正确显示时间....
编辑2
现在,在评论和答案的帮助下,我尝试了以下内容:
    DateTimeZone tz = DateTimeZone.getDefault();
    DateTime nowLocal = new DateTime();
    LocalDateTime nowUTC = nowLocal.withZone(DateTimeZone.UTC).toLocalDateTime();
    DateTime nowUTC2 = nowLocal.withZone(DateTimeZone.UTC);
    Date dLocal = nowLocal.toDate(); …