很多人在使用Postman的时候, 可能会遇到一些需要时间戳的请求, 查了一些网站各种奇奇怪怪的方法, 都不适用, 这里根据postman community的建议, 使用moment.js 的三种转换方式最简单
如下:
在Postman的Pre-request script使用的示例:
var moment = require('moment');
var current_timestamp = moment().format("YYYY-MM-DD H:mm:ss")
pm.globals.set("current_timestamp",current_timestamp);
pm.globals.set("current_unixtimestamp",moment().valueOf());
//Get UTC
console.log(moment());
//Get Unix TimeStamp
console.log(moment().valueOf());
//Get Normal TimeStamp
console.log(current_timestamp);
这样就可以配合pm.pm.variable将不同类型的时间戳应用到各个需要不同的时间戳的请求中了.