简体   繁体   中英

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 ie 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?

您可能要看一下Joda时间(http://joda-time.sourceforge.net/),其中包含一个更合理的API以处理时间。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM