1. 程式人生 > >jmeter測接口獲取當前時間函數

jmeter測接口獲取當前時間函數

當前時間 pan 好的 style end == weekend asc spa

最近有個項目涉及到上傳當天/當前周的一個總結計劃 。 這樣自動化測試接口的時候每次都需要修改日期,不勝其擾。果斷上傳獲取當前日的一個函數,在此做一下記錄:

${__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測接口獲取當前時間函數