java.util.TimeZone Date

examples/groovy/date.gvy

d = new Date()
println(d)

d += 1        // increment days by 1
println(d)

println(d.next())    // next day (incement by 1)
println(d)

println(d.seconds)
println(d.minutes)
println(d.hours)
println(d.day)
println(d.month)
println(d.year)

e = d          // create a copy
e += 3         // increment by 3 days
println(e)
println(d)
z = e-d
println(z)     // 3

Adjust Timezone in Groovy

While normally Jeruslame is at UTC+2, during the daylight saving time, it is actually UTC+3. This is reflected in the results.

examples/groovy/time_zone.gvy

import java.util.TimeZone

tz = TimeZone.getTimeZone("Asia/Jerusalem")

def ts = new Date()
println(ts)                                 // 12:43:14 UTC 2018
println(ts.format("HH:mm"))                 // 12:43
println(ts.format("HH:mm", timezone=tz))    // 15:43