1

I receive from the backend a yyyy-mm-dd string, and transform it to Date. When I transform it, local UTC is applied and depending of the UTC, the Date changes.

How to completly ignore UTC, and always have the same date of the string?

I've already tried moment.utcOffset(0) but it doesnt work in all timezones.

function parseUtcDate(date: string) {
    return moment(`${date}T00:00:00`).utcOffset(0, true).toDate();
}

Also, this Date object can't have any UTC setted, or the graphql backend will also add days when I send it.

Thanks.

  • Parse it yourself, it's not that hard: `let [y,m,d] = string.split('-'); let date = new Date(y,m-1,d);`. See [*Why does Date.parse give incorrect results?*](https://stackoverflow.com/questions/2587345/why-does-date-parse-give-incorrect-results) – RobG Feb 25 '21 at 21:46

0 Answers0