Hello everyone,
I have a problem with the display of date stored in database. When it’s displayed in a repeater using a dataset everything works but if I display its by code, nothing goes well : I have a 2h lag and my date goes to the previous day.
For demo I created a test function backend side which illustrates the problem :
Code :
export async function workWithdate(itemId) {
let dataItem = await wixData.get("Sessions", itemId);
let date = dataItem.dateDebut;
console.log("date : " + date.toLocaleDateString());
console.log("timezone " + date.getTimezoneOffset());
console.log("toUTCString() " + date.toUTCString());
return date;
}
Results :
[backend/util.js, workWithdate] called with (407f4a72-432a-4cb7-8bc7-5c3b57d73b01)
[backend/util.js, workWithdate] returned with
Fri Apr 01 2022 00:00:00 GMT+0200 (heure d’été d’Europe centrale)
date : 3/31/2022
timezone 0
toUTCString() Thu, 31 Mar 2022 22:00:00 GMT
Results interpretation :
date return by the function is correct : Fri Apr 01 2022 00:00:00 GMT+0200 (heure d’été d’Europe centrale)
but when it’s displayed by date.toLocaleDateString() or toUTCString, output is wrong.
Does anyone have tips with that ? It’s really a blocking issue !