0

Using JavaScript, I need a way to get the local time of a client.

I do have the timezone of the client formatted like this: Eastern Standard Time Mountain Standard Time Pacific Standard Time

  1. Is there a way to get the UTC offset knowing the timezone as formatted above?
  2. Or how can I get the current local time in "Pacific Standard Time"?
Peter O.
  • 32,158
  • 14
  • 82
  • 96
Jerry
  • 6,357
  • 8
  • 35
  • 50
  • Create a table of timezone names and offsets, then look it up. There is no standard for civil timezone names and some names are used for more than one timezone. – RobG May 07 '21 at 20:37
  • Can you tell us how you obtained the time zone of the client? That would help determine if those are identifiers or localized display strings. Also, be sure to read [the timezone tag wiki](https://stackoverflow.com/tags/timezone/info), especially the section titled "Time Zone != Offset". – Matt Johnson-Pint May 07 '21 at 20:38
  • Also, if you just need the local time of the client, why do you need the time zone at all? Is something wrong with `new Date().toString()`? Are you running JavaScript on the client, or are you asking about Node.js server-side code? – Matt Johnson-Pint May 07 '21 at 20:41
  • 1
    `dateObj.getTimezoneOffset()` ? https://stackoverflow.com/a/1091399/1533592 – dale landry May 07 '21 at 21:10

0 Answers0