Skip to content

new Date().get('timezone'); Always returns GMT #1355

Description

@jbgithub

The value/format returned by Date.toString() has changed. I checked this in Chrome, Firefox, Internet Explore and Edge.

I'm located in the America/Los_Angeles timezone, here is an example of what is returned:

Wed Nov 22 2017 16:47:56 GMT-0800 (Pacific Standard Time)

The regular expression use in getTimezone() always returns GMT:
this.toString() .replace(/^.? ([A-Z]{3}).[0-9]{4}.$/, '$1')
.replace(/^.*?(([A-Z])[a-z]+ ([A-Z])[a-z]+ ([A-Z])[a-z]+)$/, '$1$2$3');

I modified the first RE to remedy the issue:
this.toString() .replace(/^.* (([A-Za-z ]+)|[A-Z]{3}).$/, '$1')
.replace(/^.
?(([A-Z])[a-z]+ ([A-Z])[a-z]+ ([A-Z])[a-z]+)$/, '$1$2$3');

With this modification, PST is now returned. This works for the 4 US time zones. You will probably need additional changes for other time zones.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions