I am using the import : org.joda.time.DateTime
but while using dateTime, it does not contain DateTime.UtcNow?
I am using the import : org.joda.time.DateTime
but while using dateTime, it does not contain DateTime.UtcNow?
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.
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()) );
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);