0

I have this form

formData = {
    "startDate": "17/04/2022 01:00 AM",
    ....,
}

what ive tried so far is

var newDate = new Date(formData)

ive got Invalid date

resource: https://www.w3schools.com/js/tryit.asp?filename=tryjs_date_string_iso5

  • May be useful for you, check this https://stackoverflow.com/questions/25159330/how-to-convert-an-iso-date-to-the-date-format-yyyy-mm-dd – Sambit Apr 14 '22 at 04:41
  • 1
    You've to modify the string to match a correct date format. A simple way would be this: `const [d, M, y, h, m] = formData.startDate.split(/\/| |:/), date = new Date(y, M, d, h, m).toISOString();`. – Teemu Apr 14 '22 at 04:47
  • what i want result is like this `Thu Mar 26 2015 02:00:00 GMT+0800 (Philippine Standard Time)` –  Apr 14 '22 at 04:49
  • That's not an ISO Date. You can get a local date by dropping `.toISOString()` part from my example. There's a small mistake in the code above, the month in the date constructor should be `M - 1`. – Teemu Apr 14 '22 at 05:08

0 Answers0