Thursday, October 24, 2013

JMeter - Creating date time string using javaScript & Beanshell


For MM/DD/YYYY date string use the below functions

1. using javaScript function:
${__javaScript(var d=new Date(); var date=d.getDate(); var
month=d.getMonth()+1; $DATE=(month<10?"0"+month:month) + "/" +
(date<10?"0"+date:date) + "/" + d.getFullYear();,DATE)}

Thus __javaScript() allows multiple lines of code as long as they are
separated by ";"

2. or using BeanShell
${__BeanShell(new java.text.SimpleDateFormat("MM/dd/yyyy").format(new
Date()))}



For MM/DD/YYYY date time string use the below functions

1. or using BeanShell
${__BeanShell(new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(new
Date()))}

Reference:http://osdir.com/ml/jakarta.jmeter.user/2004-11/msg00024.html

No comments:

Post a Comment