Reputation: 175
does anybody know how to iterate the day of the date? ie. something like
new Date()+1
or
new Date().format('yyyy-MM-dd')++;
or something like that? Please let me know.
Upvotes: 0
Views: 2625
Reputation: 171094
You can also construct Ranges from Dates like so:
Date now = new Date().clearTime()
Date twoDaysTime = now + 2
(now..twoDaysTime).each {
println it
}
Which will print:
Mon Aug 13 00:00:00 BST 2012
Tue Aug 14 00:00:00 BST 2012
Wed Aug 15 00:00:00 BST 2012
Upvotes: 2
Reputation: 13122
Groovy has some elegant ways to work with date and time values, for example you can use TimeCategory.
import groovy.time.TimeCategory
use (TimeCategory) {
new Date() + 1.day
}
Upvotes: 5
Reputation: 1414
For example:
def date = new Date()
you can use
date + 1
date.plus(1)
date.next()
reference: http://groovy.codehaus.org/groovy-jdk/java/util/Date.html
Upvotes: 3