(a) Doing last-minute dates is a bad idea. Date-time can be a surprisingly thorny topic.
(b) See my answer to a similar question.
My code sample uses a third-party Joda-Time library, a popular replacement for the obviously bad java.util.Date/ Calendar classes bundled with Java.
This code is exactly what you need, although you need:
- Adjust the format for your specific needs.
- Adjust the time zones according to what you are processing.
Do most of your date work with Joda-Time. At the beginning and at the end, convert Joda-Time DateTime objects and java.util.Date objects. Lots of Q&A here in StackOverflow to show you this conversion.
Basil bourque
source share