How to Convert mongodb ISODate to string in mongoDB?

前端 未结 4 1305
悲哀的现实
悲哀的现实 2021-01-12 15:02

I have my ISODate in mongo as ISODate and I want to just that in string format with a specific datetime format.

Here is the ISODate:

ISODate(\"20         


        
4条回答
  •  星月不相逢
    2021-01-12 15:18

    I just came across this issue. There isn't anything built into ISODate turns out. So I'm converting the ISODate to JSON text, and then I do a substring to get the part I want. You can also use method on ISODate to get year, month, date separately and then combine them.

    function formatDate(isoDate){
        return isoDate.toJSON().substr(9, 20);
    }
    

提交回复
热议问题