I want to add two timestamps to a post request in Postman. The first is for Local-time and the second for GMT time. Both should be formatted as YYYYMMDDhhmmss
.
The following script displays the date and time as "2017-06-28T08:51:29", but I want the date in simple numbers.
postman.setGlobalVariable('timestampUtcIso8601', (new Date()).toISOString());
I tried formatting the date myself, but it didn't work:
var time = date.getTime();
postman.setEnvironmentVariable("currentTime", date);
How can I get the date for local and GMT in a YYYYMMDDhhmmss
format? Does Postman have built-in functionality for formatting the time and date?
environment. set('currentdate', moment(). format(("YYYY-MM-DD"))); {{$timestamp}} -> predefined variable gets the current timestamp, Since you need date the above one should work.
If it's a just timestamp you need, just add {{$timestamp}} to the request body as the value. This would give you a Unix timestamp but if you want to use a specific format - you can use moment to do this. How do I format {{$timestamp}} as MM/DD/YYYY in Postman? Show activity on this post.
In Postman, the dynamic variable {{$timestamp}} inserts the current Unix Time Stamp into a request. ( Represented as the number of seconds since January 1, 1970) "currentTime": "1510934784"
Instead use a conditional GET request. This will also tell you that the timestamp to pass to the service will need to be in a format specified in Date and Time Specification section of RFC 2822. Show activity on this post. I like the idea of passing the number of seconds since 1970.
Check out the PostMan github page issues:
https://github.com/postmanlabs/postman-app-support/issues/553
Moment.js (without locales) is available in Postman v5.1.2 and above, do go ahead and check it out. You can use moment in your scripts as follows:
var moment = require('moment');
moment('2017-01-01T10:10:10.000').format('MMMM Do YYYY, h:mm:ss a') // January 1st 2017, 10:10:10 am
Have you tried with .replace()
?
Something like date.replace(/-|:|T/g,"")
should do the trick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With