Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Groovy 计算soapui中两个日期时间之间的差异_Groovy_Soapui - Fatal编程技术网

Groovy 计算soapui中两个日期时间之间的差异

Groovy 计算soapui中两个日期时间之间的差异,groovy,soapui,Groovy,Soapui,我使用的是SoapUI免费版。我有一个REST响应,它像这样返回日期时间 <startTime>2018-02-22T17:10:00-05:00</startTime> <endTime>2018-02-22T18:05:00-05:00</endTime> 2018-02-22T17:10:00-05:00 2018-02-22T18:05:00-05:00 如何使用groovy测试步骤计算它们之间的差异(以分钟为单位)?//假设从响应中提

我使用的是SoapUI免费版。我有一个REST响应,它像这样返回日期时间

<startTime>2018-02-22T17:10:00-05:00</startTime>
<endTime>2018-02-22T18:05:00-05:00</endTime>
2018-02-22T17:10:00-05:00
2018-02-22T18:05:00-05:00
如何使用groovy测试步骤计算它们之间的差异(以分钟为单位)?

//假设从响应中提取字符串,否则需要将值提取到字符串中。。。。
//Assuming string teased out of response, if not you need to extract the value to a string....
def startString = '<startTime>2018-02-22T17:10:00-05:00</startTime>';
def endString     = '<endTime>2018-02-22T18:05:00-05:00</endTime>';

// If you have the tags, ditch them.
startString = startString.replace("<startTime>", "");
startString = startString.replace("</startTime>", "");

endString = endString.replace('<endTime>', '');
endString = endString.replace('</endTime>', '');

log.info("Now just strings... ${startString} - ${endString}");


// Convert strings to dates...
def convertedStartDate = Date.parse("yyyy-MM-dd'T'HH:mm:ssX",startString);
def convertedEndDate = Date.parse("yyyy-MM-dd'T'HH:mm:ssX",endString);

log.info("Now dates...  ${convertedStartDate} - ${convertedEndDate}");


//Use time category to tease out the values of interest...
use(groovy.time.TimeCategory) {
    def duration = convertedEndDate - convertedStartDate
    log.info( "Days: ${duration.days}, Hours: ${duration.hours}, Minutes: ${duration.minutes}, Seconds: ${duration.seconds}, etc.")
}
def startString='2018-02-22T17:10:00-05:00'; def端字符串='2018-02-22T18:05:00-05:00'; //如果你有标签,就把它们扔掉。 startString=startString.replace(“,”); startString=startString.replace(“,”); endString=endString.replace(“”,”); endString=endString.replace(“”,”); info(“现在只是字符串…${startString}-${endString}”); //将字符串转换为日期。。。 def convertedStartDate=Date.parse(“yyyy-MM-dd'T'HH:MM:ssX”,startString); def convertededDate=Date.parse(“yyyy-MM-dd'T'HH:MM:ssX”,endString); log.info(“现在日期…${convertedStartDate}-${convertedEndDate}”); //使用时间类别梳理出感兴趣的值。。。 使用(groovy.time.TimeCategory){ def持续时间=convertedEndDate-convertedStartDate log.info(“天:${duration.Days},小时:${duration.Hours},分钟:${duration.Minutes},秒:${duration.Seconds},等等”) }
感谢您及时提供解决方案。这完全符合需要。