const d = new Date(); console.log(d); // output is 2022-04-11T10:29:46.644Z
The above code showing time for GMT, but i want to print time for Ex: GMT+1 in format like "2022-04-11T10:29:46.644+01:00.
I am using postman so can not use moment-timezone My current code:
var date = new Date().toISOString(true); pm.environment.set("todaydate", date);
"errorSource": "Invalid date offset for value 2022-10-11T13:24:37.197z of offset is +01:00.
i.e value should be 2022-10-11T13:24:37+01:00
you can timezone info from new Date().getTimezoneOffset()
const timeoffset = new Date().getTimezoneOffset()
console.log(timeoffset)
//output : -330 which is GMT -330minutes
//you can convert to hours using
const inHours = timeoffset>0 ?
'-'+Math.floor(timeoffset/60).toString().padStart(2,'0')+':'+(timeoffset%60).toString().padEnd(2,'0')
:
Math.floor((-1*timeoffset)/60).toString().padStart(2,'0')+':'+((-1*timeoffset)%60).toString().padEnd(2,'0')
console.log(inHours);
If moment.js is not an option, can you can use dayjs - https://day.js.org/