1

I am using the import : org.joda.time.DateTime

but while using dateTime, it does not contain DateTime.UtcNow?

3 Answers3

3

You can use the following:

DateTime.now(DateTimeZone.UTC);

From the javadoc:

Obtains a DateTime set to the current system millisecond time using ISOChronology in the specified time zone.

Boris van Katwijk
  • 2,668
  • 4
  • 16
  • 31
1

DateTime.UtcNow is c# (.Net) :)

For java, you can look at this answer :

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()) );
Community
  • 1
  • 1
Jurion
  • 1,211
  • 11
  • 18
1

You can try like this:

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);
Rahul Tripathi
  • 161,154
  • 30
  • 262
  • 319