postman生成格式化时间
方法一:
var moment = require('moment');
var data = moment().format(" YYYYMMDDHHmmss");
console.log(data);
pm.globals.set("time", data);
最后一步是把这个data
设置到全局变量time
中
方法二:
var myDate=new Date();
var year = myDate.getFullYear();
var month = myDate.getMonth() + 1;
var date = myDate.getDate();
var hours = myDate.getHours() + 1;
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;