如何在 Postman 中配置时间戳格式?

编程入门 行业动态 更新时间:2024-10-24 21:30:41
本文介绍了如何在 Postman 中配置时间戳格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有最新版本的 Windows 版 Postman(目前为 6.3.0).不知何故,它现在以 Unix 秒数的形式返回时间戳(如 1852502400.000),而不是格式为 YYYY-MM-DDThh:mm:ss[.sss]Z 的 DateTime.

I've got the latest version of Postman for Windows (6.3.0 at the moment). Somehow it now returns timestamps as a number of Unix seconds (like this 1852502400.000) instead of DateTime in format YYYY-MM-DDThh:mm:ss[.sss]Z.

服务器端是用Java编写的微服务,字段类型是java.time.OffsetDateTime.

Server-side is microservice written in Java, type of the field is java.time.OffsetDateTime.

我应该在 Postman 中配置什么,还是取决于服务器实现?

Is there something in Postman I should configure, or is it depends from server implementation?

推荐答案

您总是可以使用 javascript 来帮助您解决这个问题.使用环境变量并在您的请求中添加该变量来代替 {{$timestamp}}.

You can always use javascript to help you with this. Make use of the environment variable and add the variable in place of the {{$timestamp}} in your request.

在您的预请求脚本中执行以下操作:

In your pre-request script do this:

let timestamp = new Date().toJSON(); pm.environment.set('timestamp', timestamp);

现在,无论您在请求中使用 {{$timestamp}} 的任何位置,都将其替换为 {{timestamp}}.

Now, wherever in your request that you were using {{$timestamp}} replace it with {{timestamp}}.

只需运行请求,您将获得以下格式的日期:"2018-09-13T18:41:02.363Z"

Just run the request and you'll get the date in this format: "2018-09-13T18:41:02.363Z"

附加信息:Postman 还内置了 MomentJS.所以你也可以利用它.

Additonal information: Postman also has MomentJS builtin. So you can make use of that too.

Danny Dainton 写了一篇关于如何在 postman 中使用 momentjs 的精彩博客:dannydainton/2018/05/21/hold-on-wait-a-moment/ !

Danny Dainton has written a great blog on how to use momentjs inside postman: dannydainton/2018/05/21/hold-on-wait-a-moment/ !

Postman 沙盒 API 参考:www.getpostman/docs/v6/postman/scripts/postman_sandbox_api_reference

Postman sandbox API reference: www.getpostman/docs/v6/postman/scripts/postman_sandbox_api_reference

更多推荐

如何在 Postman 中配置时间戳格式?

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

发布评论

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

>www.elefans.com

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