MD01
8 years agoOccasional 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
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