I want to add hours or minutes to a current date. For example I create a Date object with current time and date, and I want to increment it by 30min, how can I do such thing in Grails/Groovy ?
Date Now : Thu Jan 16 11:05:48 EST 2014
Adding 30min to Now : Thu Jan 16 11:35:48 EST 2014
I was wondering if I could do the same that we can do with add 1 to date and it moves it a day ahead.
Method SummaryGet the DST offset (if any) for the default locale and the given date. Return a Duration representing the DST difference (if any) between two dates. Deprecated. Subtract one date from the other.
The class Date represents a specific instant in time, with millisecond precision. The Date class has two constructors as shown below.
You can use TimeCategory
import groovy.time.TimeCategory currentDate = new Date() println currentDate use( TimeCategory ) { after30Mins = currentDate + 30.minutes } println after30Mins
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With