Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postman - Convert an ISO format date into a UNIX timestamp

Tags:

postman

I’m trying to convert a ISO timestamp into a UNIX timestamp to test this converted value with the current value.

The date is 2018-02-15T00:33:02.000Z

Can this be converted into a UNIX timestamp within Postman?

Thanks in advance.

like image 260
Astroflo Avatar asked Mar 29 '18 13:03

Astroflo


People also ask

How do I change the date format on a 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.

What format is Unix timestamp?

Unix epoch timestamps are supported in the following formats: 10 digit epoch time format surrounded by brackets (or followed by a comma). The digits must be at the very start of the message. For example, [1234567890] or [1234567890, other] followed by the rest of the message.

How do you pass a date in Postman Post request?

In the Params tab, enter From in the Key column. Add the start date of your timeframe in the Value column — this must be in ISO format ( YYYY-MM-DD ). In the row below, enter To in the Key column and the end date of your timeframe in the Value column.


1 Answers

You can convert this time in Postman using moment.js which comes with the native application.

var moment = require("moment")

console.log(moment("2018-02-15T00:33:02.000Z").valueOf())

This would convert the value and print it on the Postman Console if you add this to the pre-request script or Tests tab.

This is always a good site for cross checking: http://currentmillis.com/

The same could be done in native JavaScript but moment makes it much easier.

The question is very vague as to what you are trying to do but this is a basic answer.

like image 95
Danny Dainton Avatar answered Oct 16 '22 03:10

Danny Dainton