0

In mongodb I have some dates stored in a ISODate such as:

ISODate("2017-02-06T18:04:34.954+0000")

By using foo = new Date(); However, in one certain cases it shows up as a string:

"2017-10-05T20:33:59.453Z"

Is there a way of consistency getting the ISODate("2017-02-06T18:04:34.954+0000") result shown above using JavaScript?

kirby
  • 33
  • 6

3 Answers3

2

try this

let myDate = new Date();
let myISODate = myDate.toISOString();
console.log(myISODate)

hope it helps :)

jpnazar
  • 81
  • 1
  • 6
0
var javaScriptDateObject= new Date();
var newIsoString = foo.toISOString();

Referencing this question and this answer; The MongoDB driver will transform it into ISODate:

{ 
   "_id" : ObjectId("52dfe0c469631792dba51770"), 
   "last_updated" : ISODate('2014-01-22T14:56:59.301Z') 
}
Akin Okegbile
  • 1,108
  • 19
  • 36
0

The issue was unrelated to the format, ended up being a quick reboot to node to fix the issue. Thanks.

kirby
  • 33
  • 6