码迷,mamicode.com
首页 > 其他好文 > 详细

jmeter测接口获取当前时间函数

时间:2017-08-04 12:47:27      阅读:2226      评论:0      收藏:0      [点我收藏+]

标签:方法   style   获取   nbsp   当前时间   项目   mon   网上   ack   

    最近有个项目涉及到上传当天/当前周的一个总结计划 。 这样自动化测试接口的时候每次都需要修改日期,不胜其扰。果断上传获取当前日的一个函数,在此做一下记录:

${__javaScript((new Date()).getFullYear()+‘-‘+ ((new Date()).getMonth()+1) + ‘-‘ + ((new Date()).getDate()),)}

测试一下 ,的确可以获取当前时间了  但不幸的是我们接口默认的是yyyy-MM-dd的格式,但这个函数是根据日期而变化的,有时候是yyyy-M-d的格式。所以又去网上翻找 ,最后终于实现的yyyy-MM-dd的格式:

${__javaScript((new Date()).getFullYear()+‘-‘+ ((new Date()).getMonth()+1<10?"0"+((new Date()).getMonth()+1):((new Date()).getMonth()+1)) + ‘-‘ + ((new Date()).getDate()<10?"0"+(new Date()).getDate():(new Date()).getDate()),)}

接着又去找获取当前周的起止日期的显示方法,显示如下:

"weekEnd":"${__javaScript((new Date()).getFullYear()+‘-‘+ ((new Date()).getMonth()+1<10?"0"+((new Date()).getMonth()+1):((new Date()).getMonth()+1)) + ‘-‘ + (((new Date()).getDate()<10?"0"+(new Date()).getDate():(new Date()).getDate())+6-((new Date()).getDay()==0?7:(new Date()).getDay())+1),)}

"weekStart":"${__javaScript((new Date()).getFullYear()+‘-‘+ ((new Date()).getMonth()+1<10?"0"+((new Date()).getMonth()+1):((new Date()).getMonth()+1)) + ‘-‘ + (((new Date()).getDate()<10?"0"+(new Date()).getDate():(new Date()).getDate())-((new Date()).getDay()==0?7:(new Date()).getDay())+1),)}"

刚开始以为终于解决了,后来再测接口的时候发现  凡是跨着月份的周 获取的周起止日期都不对  目前还未找到好解决方法   大家有好的解决方法也可以相互交流一下

 

jmeter测接口获取当前时间函数

标签:方法   style   获取   nbsp   当前时间   项目   mon   网上   ack   

原文地址:http://www.cnblogs.com/minoz/p/7284315.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!