SOAPUI-groovy脚本无法在其中一台计算机上运行

SOAPUI-groovy脚本无法在其中一台计算机上运行,groovy,soapui,simpledateformat,Groovy,Soapui,Simpledateformat,有关日期解析,请参见下面的简单groovy脚本: def setProperty=testRunner.testCase.getTestStepByName("Properties"); Date currentDate = new Date(); String tmpDate = currentDate //setting current DateTime to corresponding property def DateTime = new Date().parse("E MMM dd

有关日期解析,请参见下面的简单groovy脚本:

def setProperty=testRunner.testCase.getTestStepByName("Properties");
Date currentDate = new Date();
String tmpDate = currentDate

//setting current DateTime to corresponding property
def DateTime = new Date().parse("E MMM dd H:m:s z yyyy", tmpDate).format("yyyy-MM-dd'T'hh:mm:ss")
setProperty.setPropertyValue('DateTime', DateTime);
此脚本在某些安装了Win 8.1、java 7或8的机器上正常工作。但对于其中一台机器(Win 8.1),它会返回一个错误

java.text.ParseException: Unparseable date: "Tue Jan 20 11:59:58 EET 2015"
有什么问题吗?脚本完全一样

真诚地,
Dmitry

你做的事情非常尴尬!你应该考虑使用你的日期直接格式:

def propertiesStep = testRunner.testCase.getTestStepByName("Properties")
propertiesStep.setPropertyValue('DateTime',
    String.format("%tFT%tT", new Date(), new Date()))

你的代码看起来很混乱。。。使用
new Date()
生成
java.util.Date
,然后在执行
String tmpDate=currentDate
时生成
String
,然后尝试获取
Date()
再次解析
tmpDate
字符串,最后解析最后一个日期以获得具有特定格式的字符串日期

我认为你必须清理一下你的代码。。。我认为您正在寻找以下内容:

def setProperty=testRunner.testCase.getTestStepByName("Properties")
def currentDate = new Date()
def dateTime = currentDate.format("yyyy-MM-dd'T'hh:mm:ss")
log.info dateTime
setProperty.setPropertyValue('DateTime', dateTime)

希望这有帮助,

抱歉,没有,没有工作,现在没有在标题中*我编辑了你的标题,但是你可以随时使用
编辑
链接
:)
。谢谢大家!我试试看。我不是开发人员,所以我的代码肯定很糟糕。@Dmitry我在上面的脚本中添加了一个额外的步骤,以获得更好的编码风格。谢谢大家的帮助。项目在所有机器上都能正常工作,客户很高兴:)@Dmitry很高兴能帮助您
:)