I'm using a ngbDatePicker
feature to select a date, which then returns an object structured like this:
{year:2020, month:12, day:03}
My goal is to convert this date into an ISOString
format with the current time. For example, if the current time is 18:42, the output should look something like this:
2020-12-03T18:42:00.000Z
To achieve this, I converted the object into a date first (the object 'model' contains the date as shown above)
var date = new Date(this.model.year + "-" + this.model.month + "-" + this.model.day);
//then I attempted to add the current time but the solution I found online didn't work for me
var date2 = new Date(date);
var isoDateTime = new Date(date2.getTime() - (date2.getTimezoneOffset() * 60000)).toISOString();
The resulting isoDateTime shows 2020-12-10T03:00:00.000Z
which is not correct.
How can I resolve this issue?
View the working code on StackBlitz