I was using javascript to show the date field in ‘mm-dd-yyyy’ format from the date input field in typescript. But since the input date value was only having the date and not time, when using the ‘new Date()’ function time was set to 00:00:00 hours GMT. This caused date to shift a day before in timezones behind GMT. In order to fix this issue, I added a local time string inside the ‘new Date()’.
dateFormatUpdate(dateValueInput) {// Convert date to mmddyyyy format
var dateValue = new Date(dateValueInput + " " + new Date().toLocaleTimeString());// Attaching local time string to date input to avoid date shift
// console.log('Values TIME', { 'dateValueInput': dateValueInput, 'dateValue': dateValue });
var dd = String(dateValue.getDate()).padStart(2, '0');
var dd = String(dateValue.getDate()).padStart(2, '0');
var mm = String(dateValue.getMonth() + 1).padStart(2, '0'); //January is 0!
var yyyy = dateValue.getFullYear();
console.log(mm + '/' + dd + '/' + yyyy);
return mm + '/' + dd + '/' + yyyy;
}