Ask a Question

adding hours to the present date with groovy

SOLVED
MD01
Occasional Contributor

adding hours to the present date with groovy

Hi Following is my code to add days to the present date, How can i add hours to the present date instead of days 

 

 

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def today = new Date()
def laterDate = today + 29 // adding 29 days
def dda = laterDate.format("yyyy-MM-dd 17:00:00")
log.info dda
assert json.expirationDate == dda
1 REPLY 1
nmrao
Champion Level 3

@MD01,

Here your go:

 

Looks like this is your question in Stackoverflow which happened to answer there already.

It would be easy if you use time category as shown below. 

 

use(groovy.time.TimeCategory) {
    def halfHourFromNow = new Date() + 2.hour 
    log.info halfHourFromNow.format("yyyy-MM-dd HH:mm:ss")
}

You can quickly check it online demo



Regards,
Rao.
cancel
Showing results for 
Search instead for 
Did you mean: