0

When I use Vuetify datetimepicker, I get the following date: "Wed Mar 16 2022 04:20:00 GMT+0100"

I need to convert this to ISO8601. But if I store this date in a variable called "date" and try to convert it like this:

date1 = new Date(date).toISOstring();

It returns an error that says "(intermediate value).toIsoString is not a function".

What am I doing wrong here? I'm assuming it's not a valid date object, but how can I then convert this mess into a working date object?

Lars
  • 3
  • 2

1 Answers1

1

This happenes when the toISOString() method is called on a value that is not a date object. To solve the error, make sure to only call the toISOString() method on valid date objects.

const d1 = new Date().toISOString();
console.log(d1); // 2022-03-10T09:15:54.224Z
  • Yeah I kind of figured, do you have an idea on how I can convert that mess from datetimepicker into a valid date object? – Lars Mar 10 '22 at 09:19
  • `new Date('Wed Mar 16 2022 04:20:00 GMT+0100')`. See more [here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date) – Oleg Naumov Mar 11 '22 at 14:26