Incorrect Date selected vs stored

I have a date-input on my view, bound directly to a field:

When I select the date, it displays correctly image . On save of the object, I apply a format on the date for display in another field, without modifying it’s value. The code to format is:
function sharedFormatDate(date) {
var d = new Date(date),
month = ‘’ + (d.getMonth() + 1).toString().padStart(2, “0”),
day = ‘’ + d.getDate().toString().padStart(2, “0”),
year = d.getFullYear();

    return [year, month, day].join('-');

}

When I go to view the object just created, the day portion is always 1 less than what I selected image. What am I doing wrong?

Update: even without the date format function provided above, the date saves as 1 day less than selected in the date-input

Most likely the type for your field/var is set to datetime and not date

When storing a date, like 1/28/2021 in a datetime field it will store it as 1/28/2021 00:00 UTC (a datetime), and if you then view that datetime in a timezone west of UTC it will look like 1/27/2021.

Update your field or variable type to date and the problem should be resolved. The data will technically still be stored @ 00:00 UTC but the display will consistent across timezones