Skip to content

Instantly share code, notes, and snippets.

@paganotoni
Forked from gfrison/groovy-date-time-operations
Created December 13, 2012 16:07
Show Gist options
  • Save paganotoni/4277476 to your computer and use it in GitHub Desktop.
Save paganotoni/4277476 to your computer and use it in GitHub Desktop.
Groovy also has a Time Category class which gives you DSL style syntax for manipulating dates. Here is an example:
import org.codehaus.groovy.runtime.TimeCategory
now = new Date()
println now
use(TimeCategory) {
footballPractice = now + 1.week - 4.days + 2.hours - 3.seconds
}
println footballPractice
which will produce output like this:
Sat Sep 27 10:00:12 EST 2008
Tue Sep 30 12:00:09 EST 2008
ref: http://groovycookbook.org/basic_types/dates_times/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment