Convert datetime format of response from epoch to datetime

I am new to Postman.
Recently I am trying to do GET method to get the data back. There is no variable in the request url. However, in the response body there is a “epoch” format which I would like to convert to normal datetime.

“epoch”: 1650758400

What I would like to see in the response body is similar to below:

“date”: 24 April 2022 00:00:00

Could you please guide me how can I do it?

Hi @thetswan

This should do it;

var utcSeconds = 1234567890;
var d = new Date(0); // The 0 there is the key, which sets the date to the epoch

Code taken from here;

1 Like

I may have misread your question. If you want to see it in the response the server returns then that’s code-based. The backend code would need to be configured to deliver the date in a certain format.

If you want to display it differently within postman after the server response is delivered to you, then the code above should work.

1 Like

I bet the built in moment.js library can help too.

Make sure you’re getting seconds back not milliseconds in the epoch or you’ll need to divide the epoch value by 1000 first.

1 Like

Thank you. Yes, I would like to update the format in the response. I am hitting API endpoint of the third party.

The format in the response will be set by the 3rd party. You will only be able to alter the date format after you have received your response.

1 Like