1

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

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

0

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

Comments

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

3 Comments

Thanks....also can you tell me if "ticks" too is c#.
@ChiragNangru:- Yes ticks is C#.
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); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.