1

I need some help on how to add hours to the present date, following is my code to add days to the present date.

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def today = new Date()
def laterDate = today + 29 // adding 29 days
laterDate = laterDate + Duration.parse("PT1H")
def dda = laterDate.format("yyyy-MM-dd 17:00:00")
log.info dda
Rao
  • 20,781
  • 11
  • 57
  • 77
peter
  • 391
  • 1
  • 4
  • 17

1 Answers1

2

It would be easy if you use TimeCategory as shown below. Just add 2.hour and 30.minutes to the date like the natural language and apply +.

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

You can quickly try it online Demo

Rao
  • 20,781
  • 11
  • 57
  • 77
  • Hi Rao, it worked thank you, can you also advise if we can add the GMT time tot he present date. – peter Jul 26 '17 at 20:32
  • @peter, The original question got answered, appreciate if accepted as answer. Regarding your question from comment, you want to add the the local timezone or GMT always? – Rao Jul 27 '17 at 00:39
  • @peter, can you try with `yyyy-MM-dd HH:mm:ssZ` format and see if that is what you are looking after? – Rao Jul 27 '17 at 00:47