0

I'm working with a javascript calendar which is very strict in it's required format. It requires dates to be in the following way:

The UTC string format I get from server = 2020-04-01T00:00:00Z. The calendar library I'm using requires this to be turned into a date object to be used.

let formattedstartDate: Date = new Date(2020-04-01T00:00:00Z);
// Wed Apr 01 2020 01:00:00 GMT+0100 (British Summer Time)

This works all fine but I need to convert this to GMT timezone before I send it to the calendar. All the examples I see with moment convert it to UTC but I need GMT.

Any ideas?

Andrew Howard
  • 2,818
  • 5
  • 33
  • 59
  • Does this answer your question? [How do you convert a JavaScript date to UTC?](https://stackoverflow.com/questions/948532/how-do-you-convert-a-javascript-date-to-utc) – kmoser Jan 14 '21 at 09:19
  • Perhaps moment is not for you then? Native JS can do a lot of stuff using INTL - also https://moment.github.io/luxon/ is an alternative – mplungjan Jan 14 '21 at 09:20
  • One more great library (Maybe helpfull): https://date-fns.org/ -- timezones: https://date-fns.org/v2.16.1/docs/Time-Zones – Ezra Siton Jan 14 '21 at 09:24

1 Answers1

0

You can use

new Date('2020-04-01T00:00:00Z').toUTCString()
// Wed, 01 Apr 2020 00:00:00 GMT

Kumar
  • 3,116
  • 2
  • 16
  • 24