Postman生成六位随机数和格式化时间的方法

6位随机数生成

需要用到for循环:

var Num="";

for ( var i=0;i<6; i++ )

{

Num += Math.floor(Math.random() * 10);

}

var Num = Math.floor(Math.random() * 10);

console.log(Num);

参考资料:https://*.com/questions/4959975/generate-random-number-between-two-numbers-in-javascript

 

生成格式化时间:

方法一:

var moment = require('moment');

var data = moment().format(" YYYYMMDDHHmmss");

console.log(data);

方法二:

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;

上一篇:记录登录时间


下一篇:CodeForces - 4B