我有最新版本的 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 中配置时间戳格式?
发布评论