I use the following script:
command: storeEval
Target: { (new Date()).getDate()+‘/’+((new Date()).getMonth()+1)+‘/’+(new Date()).getFullYear()}
Value: date
and it returns = 7/1/2019
How can I format it so that it returns 07/01/2019
Thanks in advance
What a crazy structure.
Wouldn’t this one be better?
String myDate = DateTimeFormatter.ofPattern("dd/MM/yyyy").format(LocalDate.now())
Or what do you want to do with the date?
Hi, thanks for the response
How can I modify your code so that it fits into the Katalon Recorder? Thank you.
Since storeEval uses a JavaScript snippet, you can use toLocaleDateString()
You will need to use a locale string that produces a date in the format you want. e.g. “en-GB”
The following works for me:
Command: storeEval
Target: new Date().toLocaleDateString(“en-GB”)
Value: MyDateString
Command: echo
Target: ${MyDateString}
Produces the Log entries:
#### [info] Executing: | storeEval | new Date().toLocaleDateString("en-GB" ) | MyDateString |
#### [info] Store '16/01/2019' into 'MyDateString'
#### [info] Executing: | echo | ${MyDateString} | |
#### [info] Expand variable '${MyDateString}' into '16/01/2019'
#### [info] echo: 16/01/2019
3 Likes