我正在使用SoapUI免费版。我有一个REST响应,返回像这样的日期时间
<startTime>2018-02-22T17:10:00-05:00</startTime>
<endTime>2018-02-22T18:05:00-05:00</endTime>
如何使用常规测试步骤计算它们之间的差异(以分钟为单位)?
答案 0 :(得分:2)
//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.")
}