Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add timestamp in Postman request?

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?

like image 218
Vikas Kumar Avatar asked Jun 28 '17 09:06

Vikas Kumar


People also ask

How do I add a timestamp to my postman?

environment. set('currentdate', moment(). format(("YYYY-MM-DD"))); {{$timestamp}} -> predefined variable gets the current timestamp, Since you need date the above one should work.

How do you send a timestamp in a post request?

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.

What is timestamp in Postman?

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"

How do I pass a timestamp in API?

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.


2 Answers

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
like image 23
gagneet Avatar answered Jan 04 '23 16:01

gagneet


Have you tried with .replace()? Something like date.replace(/-|:|T/g,"") should do the trick.

like image 55
klubi Avatar answered Jan 04 '23 17:01

klubi