如何在 Postman 中将 {{$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
)插入到 Postman 的请求中?
How do I insert the current date (formatted as MM/DD/YYYY
) into my request with Postman?
推荐答案
您可以将 moment.js 与邮递员给你那个时间戳格式.
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("today", moment().format("MM/DD/YYYY"));
然后在需要时参考 {{today}}
.
如果您将其添加到 Collection Level Pre-request Script
,它将为 Collection
中的每个请求运行.而不是需要将它单独添加到所有个请求中.
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.
关于在 Postman 中使用 moment
的更多信息,我写了一篇简短的博文:https://dannydainton.com/2018/05/21/hold-on-wait-a-moment/
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/
这篇关于如何在 Postman 中将 {{$timestamp}} 格式化为 MM/DD/YYYY?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!