如何在 Postman 中将 {{$timestamp}} 格式化为 MM/DD/YYYY?

编程入门 行业动态 更新时间:2024-10-28 12:22:18
本文介绍了如何在 Postman 中将 {{$timestamp}} 格式化为 MM/DD/YYYY?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在 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 的更多信息,我写了一篇简短的博文:dannydainton/2018/05/21/hold-on-wait-a-moment/

For more information about using moment in Postman, I wrote a short blog post: dannydainton/2018/05/21/hold-on-wait-a-moment/

更多推荐

如何在 Postman 中将 {{$timestamp}} 格式化为 MM/DD/YYYY?

本文发布于:2023-10-29 04:24:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1538716.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中将   格式   如何在   Postman   timestamp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!