Dates: now() is wrong when formatted

Hey there!

I noticed something strange with dates today. I am only realizing now that I am close to midnight and the timezone being off by a few hours made me notice that the day is wrong.

WeWeb

Even without using the formatDate() function, when I set the init value of a date picker to the base WeWeb now() function, it gives me the wrong date/time.

Basically, every time the current date is transformed in any way, it uses the wrong timezone. Does anyone know how I could get around this?

Thank you in advance!

The two stringified dates have two different timezones: the first one is in UTC but the second one is in UTC+8.
2023-02-03T22:00:00Z is the same time as 2023-02-04T06:00:00+08:00 just displayed in two different timezones as you can check here.

But something strange is happening. The following are simulated timezones using devtools displayed in text element, date element and date picker.

image


image


I think the behaviour you are expecting when you ask for the current time is what you get from new Date() (new Date().toISOString() if you want a string)

@dorilama Iā€™m not sure I understood your workaround in your last sentence.
No matter what date/time I feed to a date picker input, the date picker transforms the time-zone to something else.

Even if the init time given is a string, or even numerical, it always converts it.

You can see in my screenshots that if you set the initial value, of both date element and date picker element, to new Date() the correct current date is visualized without any change.

1 Like

Oh I see! Many thanks, all good!