nsfyn55
nsfyn55

Reputation: 15363

Date Best Practice

I have the following problem. I have a quartz job that runs every 5 minutes and makes a web service call retrieving a large object. The purpose of this application is that it will loop through a List in the object and capture counts from a number of categories.

One specific requirement is that each category be assigned an arbitrary window, say 9am-12pm. If we are in that window the counts get added to a rolling count continued from previous jobs, if not it is ignored.

The questions. I am loading the configurable start time(in the format 9:00am EST) and an int duration(in minutes i.e. 180) from a .properties file.

The question is what is the best way to handle this. Right now I just convert the configurable start time to long when my business class is instantiated. I use Calendar to calculate the long value of the end time. Since these are both in 1970 time, When I want to find out if now is between those two times it requires some nastiness on my part. I take the current new Date() format it, strip out the year, use the Formatter again to parse() a date in 1970 then I can do a simple long comparison with my start and end time.

I know there has to be a less ugly way to approach this. Any thoughts?

Upvotes: 1

Views: 523

Answers (1)

Arjan Tijms
Arjan Tijms

Reputation: 38163

You might want to look at Joda time (http://joda-time.sourceforge.net/), which contains a more sane API to deal with time.

Upvotes: 7

Related Questions