I need to insert data into my collection with a timestamp reflecting MY timezone, as demonstrated in the code below.
console.log("Testing time: " +new Date(new Date().getTime()+(-7*24*60*60*1000)) )
The code above yields: Testing time: Sat May 29 2021 14:59:14 GMT+0300 (East Africa Time)
...correctly indicating my current timezone!
In order to be able to query my collection based on the various times, I need to format the timestamp by appending .toISOString()
to the new Date()
function as demonstrated in the code below:
console.log("Testing time: " +new Date(new Date().getTime()+(-7*24*60*60*1000)).toISOString() )
The code above yields: Testing time: 2021-05-29T11:59:08.662Z
However NOTE that by appending .toISOString()
, the timezone changes.
How do use this format, and STILL maintain my timezone?