How to get the floor of the current time to an hour in postman

Viewed 28

I am a new postman. I want to set a variable with the floor of the current time. Example: current time is "2022-09-07T05:17:59" (UTC time) BUT I want to set a variable with the value "2022-09-07T00:00:00" (UTC time) Does anyone help me? Thanks so much!

1 Answers

This isn't a very elegant solution but should work

var floor_timestamp = new Date()
floor_timestamp.setMinutes(0)
floor_timestamp.setSeconds(0)
floor_timestamp.setMilliseconds(0)
console.log(floor_timestamp.toISOString())

pm.globals.set("timestamp", floor_timestamp)
Related