Forum Discussion
TSRAO
Occasional Contributor
Thanks KarelHusa!
Not sure how to write the Groovy Script for generating the file with Date/TimeStamp in the file name, can you please suggest me!
nmrao
2 years agoChampion Level 3
Below statement can generate dyname value using date time so that it can be used for saving the filename.
print java.time.ZonedDateTime.now().format(java.time.format.DateTimeFormatter.ofPattern("yyyyMMdd-HHmmss"))
Now, if some content needs to saved into file, below will do
def fileName = java.time.ZonedDateTime.now().format(java.time.format.DateTimeFormatter.ofPattern("yyyyMMdd-HHmmss"))
def fileContent = 'you can have your content or response into this variable'
//Save the content into file; you can also add the path below if you want file to be saved in different location
new File("${fileName}.json").write(fileContent)
Related Content
- 4 years ago