我使用的是导入: org.joda.time.DateTime
但是在使用dateTime时,它不包含DateTime.UtcNow?
发布于 2016-02-22 15:33:14
您可以使用以下内容:
DateTime.now(DateTimeZone.UTC);在javadoc中:
使用指定时区中的ISOChronology获取设置为当前系统毫秒时间的DateTime。
发布于 2016-02-22 15:31:23
DateTime.UtcNow is 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()) );发布于 2016-02-22 15:35:00
您可以像这样尝试:
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);https://stackoverflow.com/questions/35547997
复制相似问题