可以使用today';groovy中的s日期

可以使用today';groovy中的s日期,groovy,Groovy,我正在进行soapui测试,其中我想保存后缀为todaydate的请求和响应 这是我的密码: // Create a File object representing the folder 'A/B' def folder = new File( 'C:/Project/SOAPUI' ) // If it doesn't exist if( !folder.exists() ) { // Create all folders up-to and including B folder.mkdir

我正在进行soapui测试,其中我想保存后缀为todaydate的请求和响应

这是我的密码:

// Create a File object representing the folder 'A/B'
def folder = new File( 'C:/Project/SOAPUI' )
// If it doesn't exist
if( !folder.exists() ) {
// Create all folders up-to and including B
folder.mkdirs() 
}

def myOutFile = "C:/Project/SOAPUI/test_request.txt"
def request = context.expand( '${test#Request}' )

def f = new File(myOutFile)
f.write(request, "UTF-8")
=====================

我希望文件名为test_request(+今天的日期)

你能给我一些建议吗?

这里有一个选项:

def myOutFile = "C:/Project/SOAPUI/test_request_${(new Date()).format('yyyy-MM-dd')}.txt"

输出看起来像C:/Project/SOAPUI/test\u request\u 2015-08-30.txt

那么,到底是什么问题?获取今天的日期(
新日期()
)?将其格式化为字符串(使用
SimpleDateFormat
)?连接两个字符串(
字符串c=a+b;
)?这都是googleable。@JBNizet我不建议使用
SimpleDataFormat
,也不建议使用
+
运算符来连接此处的字符串。我认为这个问题是合理的,我认为@emmanuel rosa提供的答案也是合理的。只要我的2美分。