java - How to fetch the records of last 24 hours or 7 days from today's date using Joda-Time API -


i trying out hand in finding out records have been updated in oracle 11g db in last 24 hours or 7 days or 30 days. able desired functionality using "java.util.calendar"

date today = new date();  calendar cal = new gregoriancalendar(); cal.settime(today); //for last 7 days cal.add(calendar.day_of_month, -7); 

however wondering if has done joda-time api?

you need define exactly mean "last 24 hours" , "last 7 days". really mean last 24 hours, or "since same local time yesterday"? latter mean 23 hours or 25 hours, due daylight saving transitions.

if really, want 24 hours , 7 * 24 hours, use instant:

instant = new instant(); instant nowminus24hours = now.plus(durations.standardhours(-24)); instant nowminus7days = now.plus(durations.standarddays(-7)); 

note instant has no concept of time zone or calendar - it's just point on timeline; it's appropriate data type use timestamps , like.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -