Skip to content

Instantly share code, notes, and snippets.

@dariogabriel113
Last active March 22, 2019 12:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dariogabriel113/cac2236c5068fc74decc0cb71b1d14fd to your computer and use it in GitHub Desktop.
Save dariogabriel113/cac2236c5068fc74decc0cb71b1d14fd to your computer and use it in GitHub Desktop.
Add/Subtract Date Time
use (groovy.time.TimeCategory) {
//Example of Add Date 20 days from now
println new Date()
println 20.days.from.now
//Example of Add Date 3 months from now
println new Date()
println 3.months.from.now
//Example of Add Date 2 years from now
println new Date()
println 2.years.from.now
}
use (groovy.time.TimeCategory) {
//Example of Add Time 10 hours from now
println new Date()
println 10.hours.from.now
println " "
//Example of Add Time 15 minutes from now
println new Date()
println 15.minutes.from.now
}
use (groovy.time.TimeCategory) {
Date date = new Date()
//Example of Subtract Date 10 days from now
println date
println date-10.days
//Example of Subtract Date 3 weeks from now
println date
println date-3.weeks
}
use (groovy.time.TimeCategory) {
Date date = new Date()
//Example of Subtract Time 10 minutes from now
println date
println date-15.minutes
//Example of Subtract Time 45 hours from now
println date
println date-45.hours
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment