0

Let's say the user is in Sydney, and is using an application(browser) to specify that a service/change should start at 05:30 PM Indian time.

When user select a date in browser, the application get

1. Date and time - Sydney time.
2. Timezone (from a dropdown) - India time (+5:30).

Let's say user selected 5:30 PM from the widget, which is actually Sydney time (+11:00) [new Date()].

Now I want to change that selected date + time to Indian time and save that to DB in ISO format.

I want a user to select an Indian time, and then change that to ISO string, new Date().toUTCString() will convert Sydney time to UTC.

How can I do that? I tried with moment.js and new Date().toLocaleString(locale, { timezone }), but couldn't make it work.

Abhijeet Ahuja
  • 5,596
  • 5
  • 42
  • 50
  • Instead of `new Date()`, you can use `new Date().toUTCString()` – Rajesh Feb 07 '19 at 06:18
  • Yes, but I want a user to select an Indian time, and then change that to ISO string, new Date().toUTCString() will convert Sydney time to UTC. – Abhijeet Ahuja Feb 07 '19 at 06:19
  • The idea was to accept date in local timezone and convert to UTC. Then add necessary ofset and ta-da!! You can also look into [moment-timezone](https://momentjs.com/timezone/) if you is open to library – Rajesh Feb 07 '19 at 06:33

0 Answers0