Groovy Finding Past/Future Dates

1 min read
Share:

Often I found it painful working on dates when I had to find a past/future date based on weeks, months or years.

Groovy class org.codehaus.groovy.runtime.TimeCategory has very helpful & intutive syntax for working on dates.
I am sure I need not to explain what each of the following statements will do:

Date date = new Date()

use(org.codehaus.groovy.runtime.TimeCategory) {
    date = date - 10.seconds
    date = date - 10.minutes
    date = date - 10.hours
    date = date - 10.days
    date = date - 10.weeks
    date = date - 10.months
    date = date - 10.years
}

–
~Aman Aggarwal
[email protected]

http://www.IntelliGrape.com/

comments ( 1 )

  1. florin profile picture

    I’ve just picked up groovy and I am impressed. I’m waiting for my Groovy Recipes book to arrive any moment now.

    I’ve started playing around groovy within Apache Click framework and I’m amazed how cool web development can be.

    Reply ↓

Leave a Reply

Your email address will not be published. Required fields are marked *