0

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>
            </>
        )
    }

here is how the locathost looks like with vite it has +0800 in the end: enter image description here

it is my timezone and what i'd want it to look like

but it has Z at the end from the deployed one: enter image description here

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

the overall framework i'm using btw is the qwik framework deployed to cloudflare pages

  • Your date/time is being formatted on the server, which is apparently set to UTC (which for something like Cloudflare makes at least some sense). You can send the date to the client as a raw timestamp and build a Date instance at the client, where it will be formatted according to the client timezone. – Pointy Jul 21 '23 at 00:09
  • Now exactly how you *should* do this depends on your application and the semantics of the date/time value in question. That is, it may or may not make sense for the value to be anchored to some particular time zone as opposed to always being client-relative. So if your user sets up a date/time in Thailand, they see it in local time there. If they fly to England and log back in, what should they see? – Pointy Jul 21 '23 at 00:11
  • @Pointy ty for helping, how do i send the date to the client so it can be formatted in their browser instead? (new to js in general) regarding your second question, i'd like them to see the england timezone(the locale time where they are but it should be stamped with where the post was created Thailand) – greg pinakapoging nilalang sa Jul 21 '23 at 00:14
  • Make the Date (on the server) the way you're doing it, and then instead of sending the formatted date, send the output of `.getTime()`. That will be a number. On the client, you can use that number with `new Date()`. – Pointy Jul 21 '23 at 00:22

0 Answers0