Handling locale dates when SSR
I am trying to display a date with
date.toLocaleDateString
, however as the page is SSR it is instead showing as the server's locale. Is there a pattern to handle this?10 Replies
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
You mean by passing the locale in the url right?
I'm thinking if there's an easy to only render/rerender the dates on client
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Thanks will take a look at that article
The concern for me is displaying the date in the user's timezone
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Yeah I'm leaning towards 2) was wondering if anyone else has a good pattern for implementing this
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Came across this as well, would be so much better if there was a html element to do this
For my own project, I deal with this issue by setting the user's timezone to the cookies:
I have two functions:
On the very first load, it wouldn't know the time zone, however at least for my own project, there is a login page/a root page that a user loads before any times are even shown.
Thanks for sharing. I have pages that have dates on first load, so I opted to render as UTC and update on client.