Notes

Timezone Notes

Edit on GitHub

JavaScript

Timezone (zone): UTC IANA timezone format (zone names): Asia/Karachi

  • You can create a date in another timezzone
1london = new Date().toLocaleString("en-US", {timeZone: "Europe/London"});
2// "5/15/2019, 8:02:27 AM"
3
4var date1 = new Date('August 19, 1975 23:15:30 GMT+07:00'); // GMT+07
5var date2 = new Date('August 19, 1975 23:15:30 GMT-02:00'); // GMT-02
  • You can convert a UTC date to another timeZone
1// convert current datetime (PKT GMT+5 in my case)
2london = new Date().toLocaleString("en-US", {timeZone: "Europe/London"});
3
4// convert a specific datetime 
5london = new Date('2019-05-08 11:43:39 UTC').toLocaleString("en-GB", {timeZone: "Europe/London", timeZoneName: "long"})
6// "08/05/2019, 12:43:39 British Summer Time"
  • You can get the offset of a date (in minutes) with .getTimezoneOffset()
1lahore = new Date();
2// Wed May 15 2019 12:19:54 GMT+0500 (Pakistan Standard Time)
3
4lahore.getTimezoneOffset();
5// -300

https://stackoverflow.com/questions/15141762/how-to-initialize-a-javascript-date-to-a-particular-time-zone