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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -