Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.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
I';我正在尝试将2019-11-22 11:29:34.56转换为以秒为单位的历元时间戳+;在SoapUI groovy中使用1分钟_Groovy_Soapui - Fatal编程技术网

I';我正在尝试将2019-11-22 11:29:34.56转换为以秒为单位的历元时间戳+;在SoapUI groovy中使用1分钟

I';我正在尝试将2019-11-22 11:29:34.56转换为以秒为单位的历元时间戳+;在SoapUI groovy中使用1分钟,groovy,soapui,Groovy,Soapui,我想要的是获取当前日期,并将其放入测试用例中的变量中,类似于使用此时间戳转换器的156239260: 我试图将此代码作为属性值${=def now=new Date();now.format(“yyy-MM-dd”)}但格式错误 好的,我部分地解决了问题${=def now=new Date();epoch\u milis=now.getTime()} 但是我需要这个时间戳提前1分钟,在纯Groovy中: String myTime = '2019-07-04 13:21:00'

我想要的是获取当前日期,并将其放入测试用例中的变量中,类似于使用此时间戳转换器的156239260:

我试图将此代码作为属性值
${=def now=new Date();now.format(“yyy-MM-dd”)}
但格式错误

好的,我部分地解决了问题${=def now=new Date();epoch\u milis=now.getTime()}
但是我需要这个时间戳提前1分钟,在纯Groovy中:

    String myTime = '2019-07-04 13:21:00'
    Date myTimeParsed = Date.parse('yyyy-MM-dd HH:mm:ss', myTime)
    assert myTimeParsed.getTime()/1000 == 1562239260

    long epochTime = (myTimeParsed.getTime()/1000) + 60

    import java.time.Instant
    import java.util.Date
    import java.text.SimpleDateFormat

    Date sixtyLater = Date.from(Instant.ofEpochSecond(epochTime))
    assert new SimpleDateFormat('yyyy-MM-dd HH:mm:ss').format(sixtyLater) == '2019-07-04 13:22:00'        

这是正确的答案

${=def now=new Date();epoch_milis = now.getTime()+120000} 

我现在领先2分钟:D

现在。getTime()
返回时间戳,单位为毫秒。如果需要秒,只需将其除以1000:
现在。getTime()/1000
@ranger以上结果以秒为单位。再加上一分钟的秒数
(myTimeParsed.getTime()/1000)+60
@ranger我为您编辑了我的答案,添加了60秒,并将其转换回最新格式