skip to Main Content

I logged out the value stored in one of the documents(or notes in my case) in the date key, like this

console.log(notes[0].date)

The output that I got was
enter image description here

and when methods like getDate() or toDateString() didn’t work, what should i be doing?

2

Answers


  1. You will need to convert it into a javascript date object using new Date("your mongodb date string");

    See: https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/Date for more infomation

    Login or Signup to reply.
  2. If your dates are stored using the date data type you should manipulate them as data object in your code.

    If your dates are not stored using the date data type you should migrate your data to store the date as date data type rather than string.

    You then format the date, using the user’s LOCALE, only when you present it to the user.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search