2016-02-22 58 views

回答

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())); 
+0

感谢....也可以请您告诉我 “滴答” 也为C#。 –

+0

肯定:)这个答案:http://stackoverflow.com/questions/3706306/c-sharp-datetime-ticks-equivalent-in-java – Jurion

+0

@ChiragNangru: - 是[蜱是C#](https:// msdn。 microsoft.com/en-us/library/system.datetime.ticks(v=vs.110).aspx)。 –

3

可以使用如下:

DateTime.now(DateTimeZone.UTC); 

来自javadoc:

在指定时区中使用ISOChronology获取设置为当前系统毫秒时间的DateTime。

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);