当我创建一个新的Date对象时,它被初始化为当前时间,但使用的是本地时区。如何在GMT中获取当前日期和时间?
发布于 2014-01-08 21:08:38
使用UTC转换当前DateTime:
DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
DateTimeZone dateTimeZone = DateTimeZone.getDefault(); //Default Time Zone
DateTime currDateTime = new DateTime(); //Current DateTime
long utcTime = dateTimeZone.convertLocalToUTC(currDateTime .getMillis(), false);
String currTime = formatter.print(utcTime); //UTC time converted to string from long in format of formatter
currDateTime = formatter.parseDateTime(currTime); //Converted to DateTime in UTChttps://stackoverflow.com/questions/308683
复制相似问题