Java code snippet no longer working to create dates in 3.3.2, worked fine in 3.3.1 and prior builds
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Java code snippet no longer working to create dates in 3.3.2, worked fine in 3.3.1 and prior builds
I have been using the following custom property for years to create dates which I then pass for my insertion of transactions in my rest web service calls. The below example has always created the date of tomorrow in "effectiveEntryDate":09/14/2020 format.
${=import javax.xml.datatype.DatatypeFactory; def cal = Calendar.instance;cal.add(Calendar.DATE, 1);cal.getTime().toLocaleDateString()}
It worked fine in 3.3.1 but once I upgraded to 3.3.2, it now returns an error:
"effectiveEntryDate":"No signature of method: java.util.Date.format() is applicable for argument types: (String) values: [MM/dd/yyyy]
Possible solutions: from(java.time.Instant), toYear(), stream(), getAt(java.lang.String), parse(java.lang.String), print(java.io.PrintWriter)"
Is it possible I need to upgrade the java for ReadyAPI, etc? Any help would be greatly appreciated!
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @CByler
Can you please try using
For custom property:
${=import java.text.SimpleDateFormat ; new SimpleDateFormat("yyyy-MM-dd").format(new Date())}
You can update "yyyy-MM-dd" with your requirement(EX: yyyy-MM-dd'T'HH:mm:ss).
For Groovy Script:
import java.text.SimpleDateFormat
def currentTime = new SimpleDateFormat ("yyyy-MM-dd").format(new Date())
Thanks!
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The custom property worked perfectly! Let me ask one more thing. With the old java, I could modify the dates such as:
Same Day
${=import javax.xml.datatype.DatatypeFactory; def cal = Calendar.instance;cal.getTime().format("MM/dd/yyyy")}
Future Date
${=import javax.xml.datatype.DatatypeFactory; def cal = Calendar.instance;cal.add(Calendar.DATE, 1000);cal.getTime().format("MM/dd/yyyy")}
Is that possible using the SimpleDate snippets?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
1) Future date custom property with Local Date class:
${= import java.time.LocalDate; LocalDate.now().plusDays(1).format(java.time.format.DateTimeFormatter.ofPattern("MM/dd/yyyy"))}
or
${=java.time.LocalDateTime.now().plusDays(1).format(java.time.format.DateTimeFormatter.ofPattern("MM/dd/yyyy"))}
2) Future Date in groovy with Simple Date Format:
import groovy.time.TimeCategory
import java.text.SimpleDateFormat
use(TimeCategory) {
def time = new Date()+ 1.days
date = new SimpleDateFormat ("MM/dd/yyyy").format(time)
}
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks so much for your help!
