I have a date and a time stored in different strings in Typescript and I want to convert that into a Date.
It's driving me nuts because I'm in GMT-3 and the date is not what it should even though I'm using UTC.
I have 2 concerns: 1st, the date is not correct, and 2nd, is there a more "elegant" way to do this?
parseDate(date: string, time: string) : Date {
let d = new Date(Date.UTC(
Number(date.substring(0,4)),
Number(date.substring(5,7)) - 1,
Number(date.substring(8)),
Number(time.substring(0, 2)),
Number(time.substring(3))
));
return d;
}
I'm testing with date '2018-02-09' and time '10:15' and I get Thu Feb 09 2018 07:15:00 GMT-0300 (SA Eastern Standard Time)