#timezone is different between localhost and deployed version of the site

2 messages · Page 1 of 1 (latest)

plush haven
#

hello everyone 🙂 noob here

how come when i do a date it shows my locale timezone from local build (with npm run preview)
but when i deploy it to cloudflare the webpage i get is on UTC time.
i'd like it to be my timezone too

    function timeElements(date: string, time: string) {
        const timeFromString = new Date(`${date}T${time}:00.000+08:00`);

        const formattedDateString = datefns.format(timeFromString, "MMM do, yyyy | K:mm XX") // added XX here to show timezone
        const dateAttrVal = datefns.format(timeFromString, "yyyy-LL-dd KK:mm")

        return (
            <>
                <time dateTime={dateAttrVal}>{formattedDateString}</time>
            </>
        )
    }

in the images i've attached, the one that has +0800 in the end is my timezone and what i'd want it to look like but it has Z at the end from the deployed one

is there something i could specify in the webpage to force this?

uneven wharf
#

timeElements function runs on the server I guess so that's why timezone are different
To solve the problem you can move the timeElements on the client (useVisibleTask$ + signals) or force a specific timezone with datefns