我正在使用import:org.joda.time.DateTime
但是在使用dateTime时,它不包含DateTime.UtcNow?
答案 0 :(得分:3)
您可以使用以下内容:
DateTime.now(DateTimeZone.UTC);
来自javadoc:
在指定的时区内使用ISOChronology获取设置为当前系统毫秒时间的DateTime。
答案 1 :(得分:1)
DateTime.UtcNow是c#(。Net):)
对于java,你可以看看这个答案:
How can I get the current date and time in UTC or GMT in Java?
:
SimpleDateFormat dateFormatGmt = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss");
dateFormatGmt.setTimeZone(TimeZone.getTimeZone("GMT"));
//Local time zone
SimpleDateFormat dateFormatLocal = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss");
//Time in GMT
return dateFormatLocal.parse( dateFormatGmt.format(new Date()) );
答案 2 :(得分:1)
您可以尝试这样:
DateTime utc = new DateTime(DateTimeZone.UTC);
//If you want to get the time for a specific timezone then add it
DateTimeZone tz = DateTimeZone.forID("America/Los_Angeles");
DateTime dt = utc.toDateTime(tz);