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,998
  • 4
  • 17
  • 32
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,230
  • 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
  • 168,305
  • 31
  • 280
  • 331