一、根據(jù)當(dāng)前日期隨機(jī)生成一個(gè)歷史日期(格式:yyyy-mm-dd)
var num = Math.round(Math.random()*100)? //生成一個(gè)0-100的隨機(jī)數(shù)
var date = new Date()? //獲取當(dāng)前日期
var his_date = String(date.setDate(date.getDate()-num)) //設(shè)置當(dāng)前日期為num前的日期
//console.log(his_date)
//console.log(typeof his_date)
//console.log(num)
var year = String(date.getFullYear())? //獲取yyyy
var month = String(date.getMonth()) //獲取mm
var day = String(date.getDate())? //獲取dd
//console.log(year,month,day)
//console.log(typeof year)
var history_date = year+"-"+month+"-"+day? //設(shè)置日期輸出格式
//console.log(history_date)
pm.environment.set("history_date",history_date);