Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
259 views
in Technique[技术] by (71.8m points)

Jmeter how to find the difference in two time which is stored in string

I have below values String CurrentTime1=${__groovy(${__groovy(Date.parse('yyyy-MM-dd hh:mm:ss.SSS','${Modified_date_1}').getTime(),)},)} log.info("Current time1 ----> "+CurrentTime1); String beforetime=vars.get("beforetime");

log.info(" after time -->"+beforetime);

Result: Current time1 ----> 1611495406402 after time -->1611495402100

As there are stored in string, i am not able to get the difference between these values. Can you please help.

I need to get the difference between current time and before time which are dynamic values.

question from:https://stackoverflow.com/questions/65871300/jmeter-how-to-find-the-difference-in-two-time-which-is-stored-in-string

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you want to do this in Groovy - you need to convert the string to Long like:

def before = vars.get('beforetime') as long
def current =  vars.get('CurrentTime1') as long

def delta = current - before
def deltaAsString = delta as String

If you prefer using JMeter Functions - you can go for __longSum()

${__longSum(${CurrentTime1},-${beforetime},)}

enter image description here

More information on this and other JMeter Functions: How to Use JMeter Functions - Part III

But don't mix both approaches like inlining JMeter functions in Groovy code, as per JSR223 Sampler documentation:

When using this feature, ensure your script code does not use JMeter variables or JMeter function calls directly in script code as caching would only cache first replacement. Instead use script parameters.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...