cancel
Showing results for 
Search instead for 
Did you mean: 

Error when using groovy script to tomorrow's date

SOLVED
Highlighted
Occasional Contributor

Error when using groovy script to tomorrow's date

Hi 

I'm using the following script to get tomorrow's date

use(groovy.time.TimeCategory)
{
def tomorrow = new Date() + 1.day
//log.info tomorrow.format('yyyy-MM-dd\'T\'HH:mm:ssZ')
return tomorrow.format('yyyy-MM-dd\'T\'HH:mm:ssZ')
}

 

and getting the following error when I ran the above script

groovy.lang.MissingMethodException: No signature of method: java.util.Date.format() is applicable for argument types: (String) values: [yyyy-MM-dd'T'HH:mm:ssZ] Possible solutions: from(java.time.Instant), toYear(), stream(), getAt(java.lang.String), parse(java.lang.String), print(java.io.PrintWriter) error at line: 1

 

I'm very new to using a groovy script in ready API. Help would be appreciated

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Leader

Re: Error when using groovy script to tomorrow's date

You can use below code to get the desired result.

 

import groovy.time.TimeCategory
import java.text.SimpleDateFormat
use(TimeCategory) {
date = (new Date())+1.day
sdf = new SimpleDateFormat("yyyy-MM-dd\'T\'HH:mm:ssZ")
newDate = sdf.format(date)
log.info newDate
}

 


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal

View solution in original post

2 REPLIES 2
Highlighted
Community Leader

Re: Error when using groovy script to tomorrow's date

You can use below code to get the desired result.

 

import groovy.time.TimeCategory
import java.text.SimpleDateFormat
use(TimeCategory) {
date = (new Date())+1.day
sdf = new SimpleDateFormat("yyyy-MM-dd\'T\'HH:mm:ssZ")
newDate = sdf.format(date)
log.info newDate
}

 


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal

View solution in original post

Highlighted
Occasional Contributor

Re: Error when using groovy script to tomorrow's date

Thanks Himanshu, it worked. Appreciate your help

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors