0

I have been facing the problem. Postman Date format part.

I want to set to header area Date and time. like (Monday, 03-December-18 07:41:29) and I tried moment.js import package. I could have not to succeed. How to add moment js on pre-request area

I read Postman documentation but could not understand properly

anyone can help me.

ivawen
  • 43
  • 7
krish
  • 85
  • 4
  • 10
  • Possible duplicate of [How do I format {{$timestamp}} as MM/DD/YYYY in Postman?](https://stackoverflow.com/questions/47355150/how-do-i-format-timestamp-as-mm-dd-yyyy-in-postman) – moath naji Dec 11 '18 at 05:46

1 Answers1

2

make use of the environment variable add variable {{$timestamp}} in the request.

on pre request add:

var moment = require('moment')
pm.globals.set("timestamp", moment().format("LLLL"))

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

Output should look like this Thursday, September 4, 1986 8:30 PM

MomentJs format

ivawen
  • 43
  • 7
  • you dont need to import moment it is already an internal module in postman https://learning.getpostman.com/docs/postman/scripts/postman_sandbox_api_reference/. All you need is to add this into the pre request . var moment = require('moment') – ivawen Dec 11 '18 at 06:13