Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure format of timestamp in Postman?

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?

like image 563
WeGa Avatar asked Sep 13 '18 12:09

WeGa


People also ask

How do you format a timestamp?

With the fractional part included, the format for these values is ' YYYY-MM-DD hh:mm:ss [. fraction ]' , the range for DATETIME values is '1000-01-01 00:00:00.000000' to '9999-12-31 23:59:59.999999' , and the range for TIMESTAMP values is '1970-01-01 00:00:01.000000' to '2038-01-19 03:14:07.999999' .

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.

How do you post future date in Postman?

I would use “moment” with the offset from that request to get future date, previous date and future year. You can use (. format) at the end to format the result to whatever you need.


1 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

like image 177
Sivcan Singh Avatar answered Sep 28 '22 10:09

Sivcan Singh