admin管理员组文章数量:1025493
I'm trying to get the current date - 3 months and use it in a postman Pre-request script. I'm told it uses javascript, but it doesn't seem to be working.
The error I get is:
There was an error in evaluating the Pre-request Script: TypeError: startDate.setMonth is not a function
Here is what I have:
// setup start date
var startDate = Date();
startDate.setMonth(startDate.getMonth() - 3);
I'm trying to get the current date - 3 months and use it in a postman Pre-request script. I'm told it uses javascript, but it doesn't seem to be working.
The error I get is:
There was an error in evaluating the Pre-request Script: TypeError: startDate.setMonth is not a function
Here is what I have:
// setup start date
var startDate = Date();
startDate.setMonth(startDate.getMonth() - 3);
Share
Improve this question
edited Oct 17, 2018 at 1:00
jasonscript
6,1783 gold badges30 silver badges45 bronze badges
asked Apr 19, 2018 at 17:59
user117499user117499
3 Answers
Reset to default 4https://developer.mozilla/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#Syntax
JavaScript Date objects can only be instantiated by calling JavaScript Date as a constructor: calling it as a regular function (i.e. without the new operator) will return a string rather than a Date object; unlike other JavaScript object types, JavaScript Date objects have no literal syntax.
so
Date();
needs to be
new Date();
Try change var startDate = Date();
to var startDate = new Date();
As an alternative, Postman es with the moment module built in so you could do something like this:
var moment = require("moment")
var startTime = moment().subtract(3, 'months')
Or you could obviously use native JavaScript, worth knowing a couple of different ways though.
I'm trying to get the current date - 3 months and use it in a postman Pre-request script. I'm told it uses javascript, but it doesn't seem to be working.
The error I get is:
There was an error in evaluating the Pre-request Script: TypeError: startDate.setMonth is not a function
Here is what I have:
// setup start date
var startDate = Date();
startDate.setMonth(startDate.getMonth() - 3);
I'm trying to get the current date - 3 months and use it in a postman Pre-request script. I'm told it uses javascript, but it doesn't seem to be working.
The error I get is:
There was an error in evaluating the Pre-request Script: TypeError: startDate.setMonth is not a function
Here is what I have:
// setup start date
var startDate = Date();
startDate.setMonth(startDate.getMonth() - 3);
Share
Improve this question
edited Oct 17, 2018 at 1:00
jasonscript
6,1783 gold badges30 silver badges45 bronze badges
asked Apr 19, 2018 at 17:59
user117499user117499
3 Answers
Reset to default 4https://developer.mozilla/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#Syntax
JavaScript Date objects can only be instantiated by calling JavaScript Date as a constructor: calling it as a regular function (i.e. without the new operator) will return a string rather than a Date object; unlike other JavaScript object types, JavaScript Date objects have no literal syntax.
so
Date();
needs to be
new Date();
Try change var startDate = Date();
to var startDate = new Date();
As an alternative, Postman es with the moment module built in so you could do something like this:
var moment = require("moment")
var startTime = moment().subtract(3, 'months')
Or you could obviously use native JavaScript, worth knowing a couple of different ways though.
本文标签: javascriptget the date3 monthsStack Overflow
版权声明:本文标题:javascript - get the date - 3 months - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745636421a2160476.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论