java - How to extract joda DateTime belonging to specific time range? -


suppose have collection of datetimes, how can filter datetime objects have time between 10h00m , 12h30m?

for example:

new datetime(2013,1,1,10,0) - right,

new datetime(2013,1,1,16,0) - not.

parameters month, year, day not significant. ideas?

you can take advantage of joda's localtime class here :

localtime lowerbound = new localtime(10, 0); localtime upperbound = new localtime(12, 30);  list<datetime> filtered = new arraylist<>();  (datetime datetime : originals) {     localtime localtime = new localtime(datetime);     if (lowerbound.isbefore(localtime) && upperbound.isafter(localtime)) {         filtered.add(datetime);     } } 

you may need tweak inclusive or exclusive, localtime comparable, , on top of that, has friendly compare methods readability.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -