Groovy date ranges


/ Published in: Groovy
Save to your folder(s)

Groovy ranges works on dates also!
(http://kousenit.wordpress.com/2009/02/02/groovy-groundhogs/)


Copy this code and paste it in your HTML
  1. def cal = Calendar.instance
  2. cal.set(2009,Calendar.FEBRUARY,2)
  3. def ghday = cal.time
  4. cal.set(2009,Calendar.MARCH,21)
  5. def spring = cal.time
  6. def days = (ghday..spring).size()
  7. println "Between Feb 2 and Mar 21, there are $days days"
  8. // will print Between Feb 2 and Mar 21, there are 48 days

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.