如何在 Postman 中配置时间戳格式? [英] How to configure format of timestamp in Postman?

查看:122
本文介绍了如何在 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 的精彩博客:https://dannydainton.com/2018/05/21/hold-on-wait-a-moment/

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

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

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

这篇关于如何在 Postman 中配置时间戳格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆