/
How can I manipulate with datetimes?
How can I manipulate with datetimes?
Question
I am working with the following date format:
def targetTimestamp = api.targetDate()?.format("yyyy-MM-dd") + 'T' + (new Date()).format("HH:mm:ss")
How can I subtract or add 5 minutes?
Answer
You can use the Calendar instance to add/subtract part of the date.
def cal = Calendar.getInstance()
cal.add(Calendar.MINUTE, -5)
def targetTimestamp = api.targetDate()?.format("yyyy-MM-dd") + 'T' + (cal).format("HH:mm:ss")
Or another option is:
def dt = new DateTime(api.targetDate())
return dt.plusMinutes(5)
Note that api.targetDate()
gets you the time midnight (basically the day part only).
The DateTime object is of type org.joda.time.DateTime.
, multiple selections available,
Related content
How to Get Date Time for Specific Timezone and Date in Specific Format
How to Get Date Time for Specific Timezone and Date in Specific Format
More like this
Get Datamart Time Dimension from a Date
Get Datamart Time Dimension from a Date
More like this
Date Time Functions
Date Time Functions
Read with this
Date & Time
Date & Time
More like this
Configure Business Calendar
Configure Business Calendar
Read with this
How do I get today's date in a Groovy script?
How do I get today's date in a Groovy script?
More like this
Found an issue in documentation? Write to us.