I'm having trouble formatting the birthday date in the format 2021-04-13T00:00:00.000Z the date is sent correctly, but after this formatting it always has 1 day less. Can anyone help?
export function format(date): string {
const mydate = new Date(date);
return new Intl.DateTimeFormat().format(mydate);
}
Using the basic Date methods .getUTCYear(), .getUTCMonth(), and .getUTCDay() will enable you to get the date as it appears in your UTC-relative source string. As noted in a comment, your apparent date when rendered in your local time zone is one day earlier, as is correct for time zones west of UTC.
You can still make use of Intl.DateTimeFormat() if you pass in an option to use UTC as the time zone:
return new Intl.DateTimeFormat("pt-BR", { timeZone: "UTC" }).format(dateInput);
However, that's not supported by IE11 (if that's important to you).