2016-02-22 61 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);