I'm using react-datePicker library which takes new Date() as input.
Here I'm taking input date, time & timezone. How I can save this in the backend such that if the user selects the date Feb 10 2024 & time 02:00 & timezone BST irrespective of the location user should see the date as Feb 10 2024 02:00 BST in Date Object?
Right now new Date("2024-02-10T03:00:00.000Z") is giving me Sat Feb 10 2024 08:30:00 GMT+0530 (India Standard Time). I want this should be `Sat Feb 10 2024 08:30:00 GMT+0100 (British Summer Time).
I already tried:
const tzname = "Europe/London";
const longOffsetFormatter = new Intl.DateTimeFormat("en-US", {timeZone: tzname ,timeZoneName: "longOffset"});
const longOffsetString = longOffsetFormatter.format(new Date("2024-02-10T03:00:00.000"));
Moment.js could be helpful but it is legacy so not advised to use.
How I can save the Date based on the passed timezone instead local timezone?
Try using
luxonwhich provide modern alternatives to Moment.js and offer support for timezones.The output is now