Search code examples
javascriptreactjsmongoose

json date format to YYYY-MM-DD from 2001-09-10T21:00:00.000Z


i got this json file

    {
    other arguments
      "releaseYear": "9/11/2001",
     other arguments
  
    },

the releaseYear argument is formmated like that in the front-end 2001-09-10T21:00:00.000Z and i want it be like that 2001-09-10 and i got an input type date and got the same formmat as the first one and want it be like YYYY-MM-DD

trying to fix this date formmat


Solution

  • the thing you're trying to do here can easily be solved via packages like dayJS or momentJS.

    1. Install momentJS in your project using npm install moment --save or yarn add moment (based on your project npm/yarn)
    2. Use it like moment(releaseYear).format('YYYY MM DD');

    For extensive formatting guide, read here: https://momentjs.com/docs/#/parsing/string-format/