Skip to content

Instantly share code, notes, and snippets.

@nobusue
Created October 10, 2010 09:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nobusue/619108 to your computer and use it in GitHub Desktop.
Save nobusue/619108 to your computer and use it in GitHub Desktop.
// g100pon #92 TimeCategory
def now = new Date()
use (groovy.time.TimeCategory) {
//このクロージャの内部のみ、Integer型にメソッドが追加されたことになる
//例えば以下のようにして9時間5分後を求めることが可能
tgt = now + 9.hours + 5.minutes
}
// Date.format()はGDK(SimpleDateFormatのショートカット)
println now.format('yyyy/MM/dd HH:mm:ss')
println tgt.format('yyyy/MM/dd HH:mm:ss')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment