gpt4 book ai didi

java - Karate 框架 : how to get timestamp and append to a variable

转载 作者:行者123 更新时间:2023-12-01 23:43:36 60 4
gpt4 key购买 nike

我想获取系统时间戳并将其附加到文件名

Scenario: fielanem timestamp
* def filename = 'samplefilename.txt'
* def timestamp = java.type("java.time.localdatetime").now()
* print timestamp

我需要获取当前时间戳并将其附加到文件名。输出:样本文件名YYYYMMDDHHMMSS.txt

最佳答案

你可以使用时间戳

* def getDate =
"""
function() {
var SimpleDateFormat = Java.type('java.text.SimpleDateFormat');
var sdf = new SimpleDateFormat('yyyyMMddHHmmss');
var date = new java.util.Date();
return sdf.format(date);
}
"""

* def temp = getDate()
* print temp
* def filename = 'samplefilename.txt'
* def finalfilename = filename.split('.')[0]+temp+'.txt'
* print finalfilename

关于java - Karate 框架 : how to get timestamp and append to a variable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64667982/

60 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com