其他分享
首页 > 其他分享> > Postman生成六位随机数和格式化时间的方法

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://stackoverflow.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;

标签:10,格式化,Postman,min,六位,myDate,hours,seconds,var
来源: https://www.cnblogs.com/chuchu5811/p/10943761.html