Forum Discussion

Deepika_Lalam's avatar
Deepika_Lalam
Regular Visitor
5 years ago
Solved

Add minutes to current date time using groovy

To get the Current Date Time value, im using this:
${= Calendar.getInstance(TimeZone.getTimeZone('GMT')).format("yyyy-MM-dd'T'HH:mm:ss")}

which gives DateTime as 2020-02-05T22:07:34

 

I want to add 40 minutes to the current DateTime Value:
the expected result should be currentTime + 40 min. Which is: 2020-02-05T22:47:34

  • Deepika_Lalam 

    With Java 8, below should get you the time you needed in one liner

     

    ${= java.time.ZonedDateTime.now(java.time.ZoneId.of("GMT")).plusMinutes(40).format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"))}

     

1 Reply

  • nmrao's avatar
    nmrao
    Champion Level 3

    Deepika_Lalam 

    With Java 8, below should get you the time you needed in one liner

     

    ${= java.time.ZonedDateTime.now(java.time.ZoneId.of("GMT")).plusMinutes(40).format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"))}