Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a new Joda DateTime truncated to the last hour? [duplicate]

I am pulling timestamps from a file that I want to create a new DateTime for, but I want to create the DateTime at the floor of the hour (or any Joda Period will do).
How Can I do this?

like image 861
WolfmanDragon Avatar asked Jul 30 '09 17:07

WolfmanDragon


People also ask

Is Joda DateTime deprecated?

So the short answer to your question is: YES (deprecated).

Does Joda DateTime have timezone?

Adjusting Time ZoneUse the DateTimeZone class in Joda-Time to adjust to a desired time zone. Joda-Time uses immutable objects. So rather than change the time zone ("mutate"), we instantiate a new DateTime object based on the old but with the desired difference (some other time zone). Use proper time zone names.

What is Joda?

Joda-Time is the most widely used date and time processing library, before the release of Java 8. Its purpose was to offer an intuitive API for processing date and time and also address the design issues that existed in the Java Date/Time API.


1 Answers

Wohoo, found it. Simple like everything in Joda once I traced down the calls.

DateTime dt = new DateTime().hourOfDay().roundFloorCopy(); 
like image 137
WolfmanDragon Avatar answered Oct 23 '22 17:10

WolfmanDragon