0

Im working on a small personal react project, and here is my code:

<input name="date" type="datetime-local" value={state.newVariable.date} onChange= {handleChange}/>

My goal is to have my date go from yyyy-mm-ddthh:mm:ss to MM-DD-YY mm:ss

I read the moment js documentation but where would I start with the moment method? I appreciate any help, also to add I'm a self taught newbie.

new_be_Jeff
  • 95
  • 1
  • 11
  • The Moment.js team recommends [not to use it in new projects](https://momentjs.com/docs/#/-project-status/) as it is now a legacy project in maintenance mode. But it sounds like you want to [parse](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse) an ISO 8601 date string into another format. You can use some standard [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) methods for that, or a library like [`date-fns`](https://www.npmjs.com/package/date-fns). – j1mbl3s Jun 12 '21 at 22:29
  • You don't need a library: `let [y, m, d] = s.split(/\D/); console.log(\`${m}-${d}-${y}\`)`. However, much better to us an unambiguous format that uses the month name. – RobG Jun 13 '21 at 20:28

0 Answers0