If I was to given a specific java.util.Date, how can I generate a start and end of that given date. For example, I my date is August 25, 2011, then my start date would be August 25, 2011 00 00 00 and my end of date would be August 25, 2011 23 59 59
Background: (Read below if you want to know why I ask this question)
I use JPA to map date to my MySql database like this. I want the date to have time as well, so I use TemoporalType.TIMESTAMP
@Temporal(TemporalType.TIMESTAMP)
private Date dateProcess; //java.util.Date
I need to query all data given a specific date, and since date is stored as above, I need a date range to achieve what I want.
My game plan is to convert java.util.Date to JodaTime#DateTinme, then construct the start and end date there, and convert it back so that I can pass as parameters to JPQL. But it seems that JodaTime is very immutable, I cant seem to see a setter method any where.
A
java.util.Daterepresents an instant in time, with no reference to a time zone or calendar. The same instant will have a very different start/end of day depending on the time zone of the observer.You could do something like:
From the last two variables, you can get back to
java.util.Datevalues if you want. Usually they’ll both be midnight, but they might not be.Note that you should use the start of the next day in an exclusive way, rather than the last second of the current day in an inclusive way, in order to avoid missing values such as August 25, 2011 23:59:59.500…