简体   繁体   English

如何将 Postman Query Param 设置为今天的日期?

[英]How to set Postman Query Param to todays date?

I am trying to get the data from a period of time.我试图从一段时间内获取数据。 They are set to actual dates but I wanted to know if it was possible to always have it set to today's date without having to go back and change it every time.它们设置为实际日期,但我想知道是否可以始终将其设置为今天的日期,而不必每次都返回更改。 query params查询参数

You can add the following in the "Pre-request Script" heading below the URL field.您可以在 URL 字段下方的“预请求脚本”标题中添加以下内容。

postman.setGlobalVariable('currentDate', (new Date()).toISOString());

Then add the variable wherever you are wanting to use the current date然后在您想要使用当前日期的任何地方添加变量

{{currentDate}}

For example passing the current date as a query param例如将当前日期作为查询参数传递

www.example.com/path?date={{currentDate}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM