How to configure format of timestamp in Postman?

Viewed 18092

I've got the latest version of Postman for Windows (6.3.0 at the moment). Somehow it now returns timestamps as a number of Unix seconds (like this 1852502400.000) instead of DateTime in format YYYY-MM-DDThh:mm:ss[.sss]Z.

Server-side is microservice written in Java, type of the field is java.time.OffsetDateTime.

Is there something in Postman I should configure, or is it depends from server implementation?

2 Answers

You can always use javascript to help you with this. Make use of the environment variable and add the variable in place of the {{$timestamp}} in your request.

In your pre-request script do this:

let timestamp = new Date().toJSON();
pm.environment.set('timestamp', timestamp);

Now, wherever in your request that you were using {{$timestamp}} replace it with {{timestamp}}.

Just run the request and you'll get the date in this format: "2018-09-13T18:41:02.363Z"


Additonal information: Postman also has MomentJS builtin. So you can make use of that too.

Danny Dainton has written a great blog on how to use momentjs inside postman: https://dannydainton.com/2018/05/21/hold-on-wait-a-moment/ !

Postman sandbox API reference: https://www.getpostman.com/docs/v6/postman/scripts/postman_sandbox_api_reference

you can use $isoTimestamp variable in postman

Related