'Add days to current date in groovy
I am trying to get the current date and change the format and add 30 days to it, i tried the following in groovy :
def date = new Date().format("yyyy-MM-dd")
def laterdate = date + 30
log.info laterdate
I get the output as (formatting looks good)
Mon Jul 24 12:24:04 MST 2017:INFO:2017-07-2430
can someone please advise where i am doing wrong
Solution 1:[1]
To add days:
Date date = new Date().plus(30)
To Substract days:
Date date = new Date().plus(-30)
Solution 2:[2]
def today = new Date()
def yesterday = today + 30
log.info today.format("yyyy-MM-dd")
log.info yesterday.format("yyyy-MM-dd")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Gelberth Amarillo Rojas |
| Solution 2 | peter |
