user1730789
user1730789

Reputation: 5177

Java JodaTime get the current DateTime

I am the using the Joda library to get the current DateTime in Java. Now I use

DateTime dt = DateTime.now();

to get the current date time object. Now how can I obtain the current time of the day in non military format?

Upvotes: 1

Views: 3829

Answers (1)

Eric Wich
Eric Wich

Reputation: 1544

Right from the Java docs: http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html

What you're looking to do seems to be the first example there:

 DateTime dt = new DateTime();
 DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
 String str = fmt.print(dt);

If it's not the exact format that you're looking for, Java docs will show you the way.

Upvotes: 2

Related Questions