I have this problem. I need to do the following:
For example. Today Date is 12-January-2012 19:00
How can i make a new date, which will be 12-January-2012 00:00 (the start of the current day)
It may seems easy, but i couldnt find any groovyway to get it, any help would be apreciated.
To get the date at midnight use Date.clearTime
(docs):
dateAtMidnight = new Date()
dateAtMidnight.clearTime()
(Javadocs are for Groovy JDK < 2.0, clearTime()
is declared void
in Groovy JDK 2.0, preventing d = new Date().clearTime()
. Comments indicate the original functionality may be restored, yay!)
For the comparison, instead of using <= 23:59:59
, use < (the next day)
:
(aDate >= dateAtMidnight) && (aDate < (dateAtMidnight + 1))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With