let res = pm.response.json();
let date = res.gpsTime.split(‘T’)[0];
console.log(date)
2023-07-28
pm.collectionVariables.set(“Date”, “date”);
let time = res.gpsTime.split(‘T’)[1].slice(0,8);
console.log(time)
11:51:39
pm.collectionVariables.set(“Time”, “time”);
You need to pass in the response timestamp to the moment function.
For example.
let responseTimestamp = "2023-07-28T11:51:39+00:00";
// you need to retrieve this element from your response
const moment = require("moment");
let timestamp1 = moment(responseTimestamp).format("YYYYMMDD");
console.log(timestamp1); // "20230728"
pm.collectionVariables.set("timestamp1", timestamp1);
let timestamp2 = moment(responseTimestamp).format("hhmmss"); // needs to be lowercase
console.log(timestamp2); // "115139"
pm.collectionVariables.set("timestamp2", timestamp2);