As I delve into the realm of time zones for the first time, I've heard tales of how challenging it can be for developers. To ensure I am on the right track, I am posing this question as a safeguard to make sure nothing is overlooked.
My scenario is quite straightforward - I aim to implement a date time picker that allows users to select their date and time in their local timezone (meaning what they see in the picker matches their computer's configured date and time).
The goal is to take the selected date and time, convert it to UTC, and then transmit it to the server for storage.
Upon revisiting certain pages, I intend to retrieve the UTC date/time from the server, convert it to the user's local date/time, and present it in a user-friendly format.
Should I rely on libraries like moment timezone
for these tasks, or will the browser's built-in date methods such as Intl.DateTimeFormat
, new Date().getTimezoneOffset()
, suffice? (Considering support for only the latest modern browsers, my concern is whether these methods serve my needs rather than focusing on browser compatibility.)
It appears that all I require are 2 essentials:
- A means to obtain the user's timezone offset from UTC (to facilitate the conversion between their local time and UTC for transmission to the server, as well as converting UTC back to their local time for display on specific pages)
- A method to fetch their timezone abbreviation (such as EST, PDT, CDT) for display in the UI
Do I necessitate the use of libraries for these operations? If not, what prompts the utilization of extensive libraries when dealing with time zones?