如何在邮递员中将{{$ timestamp}}格式化为MM / DD / YYYY? [英] How do I format {{$timestamp}} as MM/DD/YYYY in Postman?
问题描述
在Postman中,动态变量 {{$ timestamp}}
将当前 Unix时间戳插入请求中。 (表示为自1970年1月1日以来的秒数)。
In Postman, the dynamic variable {{$timestamp}}
inserts the current Unix Time Stamp into a request. (Represented as the number of seconds since January 1, 1970)
"currentTime": "1510934784"
但是,我正在使用的API期望时间戳的格式为 MM / DD / YYYY
。
However, the API I am working with expects timestamps formatted as MM/DD/YYYY
.
"currentDate": "11/17/2017"
如何在请求中插入当前日期(格式为 MM / DD / YYYY
)
How do I insert the current date (formatted as MM/DD/YYYY
) into my request with Postman?
推荐答案
您可以使用 moment.js 和Postman一起为您提供时间戳格式。
You could use moment.js with Postman to give you that timestamp format.
您可以将其添加到请求前脚本中:
You can add this to the pre-request script:
const moment = require('moment');
pm.globals.set("timestamp", moment().format("MM/DD/YYYY"));
然后引用 {{timestamp}}
如果将其添加到集合级别预请求脚本
,它将运行集合
中的每个请求。无需将其分别添加到 all 个请求中。
If you add this to the Collection Level Pre-request Script
, it will be run for each request in the Collection
. Rather than needing to add it to all the requests individually.
有关在邮递员中使用时刻
的更多信息,我写了一篇简短的博客文章:> https://dannydainton.com/2018/05/21/hold-on-wait-片刻/
For more information about using moment
in Postman, I wrote a short blog post: https://dannydainton.com/2018/05/21/hold-on-wait-a-moment/
这篇关于如何在邮递员中将{{$ timestamp}}格式化为MM / DD / YYYY?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!