How to convert any past or future date to epoch time stamp using postman

40 Views Asked by At

I need to covert 12/02/2024 to epoch timestamp in postman

I attempted to manipulate the present date by adding or subtracting days as needed, but the outcome did not meet my expectations.

var admissionDatePrePaid = pm.environment.set("admissionDatePrePaid",  new Date().getTime());

but this resulted in 13 digits, but my requirement was getting 10 digits

1

There are 1 best solutions below

0
Bench Vue On

Math.floor() will address your problem,

var admissionDatePrePaid = pm.environment.set("admissionDatePrePaid", Math.floor(new Date().getTime()/1000));

Demo In Pre-request Script,

console.log("timestamp milli-seconds: ", new Date().getTime());
console.log("timestamp seconds with dot`: ", new Date().getTime()/1000);
console.log("timestamp Seconds: ", Math.floor(new Date().getTime()/1000));

Result in console

timestamp milli-seconds: 1708454492292
timestamp seconds with dot: 1708454492.293
timestamp Seconds: 1708454492

enter image description here