1. 使用脚本
//获取当前时间,并设置环境变量
//获取时间
var moment = require('moment');
//定义时间格式
var data = moment().format(" YYYY-MM-DD HH:mm:ss");
pm.environment.set("timenow",data);
console.log("timenow",timenow);
2. 自带变量
{{$timestamp}}
3. 自定义时间,
var myDate=new Date();
var year = myDate.getFullYear();
var month = myDate.getMonth() ;
var date = myDate.getDate();
var hours = myDate.getHours();
var min = myDate.getMinutes();
var seconds = myDate.getSeconds();
hours = hours < 10 ? "0" + hours : hours;
min = min < 10 ? "0" + min : min;
seconds = seconds < 10 ? "0" + seconds : seconds;
var date = year + "/" + month + "/" + date +" "+ hours + ":" + min + ":" + seconds;
console.log("date",date);
4. 实际灵活使用:
var myDate=new Date();
var year = myDate.getFullYear();
var month = myDate.getMonth() + 1;
var date = myDate.getDate()+1;
var date = year + "-" + month + "-" + date +" " + "10:00:00";