admin管理员组文章数量:1287583
{
"name": "IronMan",
"phone_number": "555555555",
"number_of_guest": 10,
"tables": [
2
],
"reservation_start_at": "2020-10-15T10:00:00.861873Z",
"reservation_end": "2020-10-15T11:00:00.861873Z"
}
{
"name": "IronMan",
"phone_number": "555555555",
"number_of_guest": 10,
"tables": [
2
],
"reservation_start_at": "2020-10-15T10:00:00.861873Z",
"reservation_end": "2020-10-15T11:00:00.861873Z"
}
I am stuck at step where I need to generate future date and time with time zone to send a postman request. The request is about a reservation feature.
On the request body,a key-value is,
"reservation_start_at": "2020-10-15T10:00:00.861873Z"
My question is, how do I generate future date and time for each request?
Thanks in advance .
Share Improve this question edited Mar 8, 2022 at 7:02 Christian Baumann 3,4444 gold badges24 silver badges45 bronze badges asked Oct 12, 2020 at 4:53 TQJTQJ 852 silver badges6 bronze badges 3-
how far into the future? change
2020-10-15T10:00:00.861873Z
to2020-10-15T10:00:01.861873Z
- now it's 1 second into the future ... similarly for minuts, hours, days months and years – Jaromanda X Commented Oct 12, 2020 at 5:06 - What did you already try? What concrete issues are you facing? Thanks for considering How do I ask a good question? and How to create a Minimal, Reproducible Example. – Christian Baumann Commented Oct 12, 2020 at 5:21
- Future means, lets say tomorrow or 1 week later. I have tried using monet.js with add. But the issue I am facing is mainly, I want a future date, like 18th October 2 PM in string format. but using the moment.js add (7, 'days') I can only get 7 days in future..but I don't know how would I get the 2 PM or 3PM at that future date. – TQJ Commented Oct 12, 2020 at 5:24
2 Answers
Reset to default 7You can use the following in postman's pre-request script:
var moment = require('moment');
const yearsInTheFuture = 1;
const monthsInTheFuture = 2;
const daysInTheFuture = 3;
const hours = 12;
const minutes = 34;
const seconds = 56;
const milliseconds = 789;
const durationInDays = 7;
const reservation_start_at = moment()
.add(yearsInTheFuture, 'years')
.add(monthsInTheFuture, 'months')
.add(daysInTheFuture, 'days')
.hours(hours)
.minutes(minutes)
.seconds(seconds)
.millisecond(milliseconds);
reservation_end = moment()
.add(yearsInTheFuture, 'years')
.add(monthsInTheFuture, 'months')
.add(daysInTheFuture + durationInDays, 'days')
.hours(hours)
.minutes(minutes)
.seconds(seconds)
.millisecond(milliseconds);
console.log("reservation_start_at: " + reservation_start_at);
console.log("reservation_end: " + reservation_end);
pm.environment.set("reservation_start_at ", reservation_start_at);
pm.environment.set("reservation_end", reservation_end);
It will set the environment variables reservation_start_at
and reservation_end
, which you then can access in the request body:
{
"name":"IronMan",
"phone_number":"555555555",
"number_of_guest":10,
"tables":[
2
],
"reservation_start_at":"{{reservation_start_at}}",
"reservation_end":"{{reservation_end}}"
}
Please try below script to generate today's date + 10 days
var moment = require('moment');
pm.environment.set("futuredate", moment().add(10, 'day').format("MM/DD/YYYY"));
本文标签: javascriptHow to generate future date and time for postman requestStack Overflow
版权声明:本文标题:javascript - How to generate future date and time for postman request - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741241688a2364104.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论