Groovy Finding Past/Future Dates

06 / Apr / 2009 by Aman Aggarwal 1 comments

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
aman@intelligrape.com

http://www.IntelliGrape.com/

FOUND THIS USEFUL? SHARE IT

comments (1 “Groovy Finding Past/Future Dates”)

  1. florin

    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 comment -