Convert response time to seconds

I am getting response time for an API but need to convert it to seconds and display. Can someone please help me on this?

Code:

var time = pm.response.responseTime

pm.test("Response time is less than 10 seconds. Time taken is: "+ time + ' ms', function() {
    pm.expect(pm.response.responseTime, "Response time was longer than 10 seconds").to.be.below(10000);
});

As of now time is displayed in milli seconds and want it to be displayed in seconds. Or I can do it with a simple math as below?

timeinseconds = time/1000;

/1000 is the common way to convert milliseconds to seconds, so if that works then it should be fine.

1 Like

You could also use the new Date() object and the different methods to get specific granular time values.

let time = new Date(pm.response.responseTime);

console.log(pm.response.responseTime);
console.log(time.getSeconds());
1 Like

Thanks a lot, Danny. It worked perfectly.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.