I have an application hosted on heroku. So every date that is generated there in api and returned to the front always returns a day late. Already my front, is hosted in Hostinger, so, ends up conflicting the dates because of timezone.
I've tried this:
document.getElementById("data").addEventListener("input", function(){
var data = document.getElementById("data").value;
var d = new Date(data);
var options = {week: "long", year: "numeric", month: "long", day: "numeric", timezone: "America/Sao_Paulo"}
var year = d.getFullYear();
var month = (d.getMonth() < 10) ? "0" + d.getMonth() : d.getMonth();
var day = ((d.getDate() + 1) < 10) ? "0" + (d.getDate() + 1) : (d.getDate() + 1);
var hour = d.getHours();
var minutes = d.getMinutes();
//options.timezone = 'America/Santa_Isabel';
var dataFormatada = new Date(Date.UTC(year, month, day, hour, minutes, 0));
var dataExtensa = dataFormatada.toLocaleString('pt-BR', options);
var dataSimples = dataFormatada.toLocaleString({timezone: 'America/Sao_Paulo'});
document.getElementById("dataSimples").innerHTML = "Data simples " + dataSimples;
})
<input type="date" placeholder="Data" id="data"/>
<p id="dataSimples"></p>
But it does not work. I need that any date that is created, always be the timezone of Brazil, then, any date passed to the api or created there, have this timezone as default. Any suggestions for resolving this?