如何在 java 中获取秒数的 UTC 时间?

How to get UTC time with seconds in java?

http://time.is/UTC 显示正确的秒数。

我将本地时钟调慢了 5 秒来进行测试。 我试过 JodaTime,还有这个。现在是我的当地时间。

    NTPUDPClient timeClient = new NTPUDPClient();
    InetAddress inetAddress = InetAddress.getByName(TIME_SERVER);
    TimeInfo timeInfo = timeClient.getTime(inetAddress);
    long returnTime = timeInfo.getReturnTime();
    Date time = new Date(returnTime);
    System.out.println("Time from " + TIME_SERVER + ": " + time);

输出: 时间 time.nist.gov:2015 年 4 月 20 日星期一 06:44:20 CDT

Time.IS 输出: 6:44:25上午

我需要精确到秒的 UTC 时间。

创建一个以 UTC 作为时区的新 DateTime

final DateTime now = new DateTime(returnTime, DateTimeZone.UTC);
final Date javaDate = now.toDate();