如何在 Postman 的当前时间戳中添加更多时间?时间、更多、如何在、Postman

2023-09-07 11:03:11 作者:✎﹏往事伤痕

我知道我可以像这样将当前时间戳添加到请求中:

I know I am able to add current timestamp into Request like this:

postman.setEnvironmentVariable('pickUpTime',(new Date()).toISOString());

但是,我想在 Postman 的当前时间戳上增加 10 分钟.我该怎么做?

However, I want to add 10min later to the current timestamp of Postman. How can I do that?

似乎我不能这样做:

postman.setEnvironmentVariable('pickUpTime',(new Date() + 10000).toISOString());

推荐答案

可以使用moment.js,它使这类事情变得如此简单和易于管理.

You can use the add function of moment.js within Postman, it makes this type of thing so simple and easy to manage.

var moment = require("moment")

pm.environment.set('pickUpTime', moment().add(10, 'minutes').toISOString())

这将使用较新的语法将此值设置为环境变量.

This will set this value to an environment variable, using the the newer syntax.