Home > Mobile >  Default Timezone is incorrect for only my site when running new Date();
Default Timezone is incorrect for only my site when running new Date();

Time:12-06

Okay so I am deving a new React site and and playing around with some time stuff and realised that when using the dev tools and running a

new Date()

I get back

Fri Dec 03 2021 03:55:44 GMT 0000 (Greenwich Mean Time)

However since I am in the Australian Timezone I expect that this should come back as

Fri Dec 03 2021 14:55:44 GMT 1100 (Australian Eastern Daylight Time)

So my first thought was that my system timezone was out of whack, however when I tried the same on any other website, (open dev tools and run new Date()) I get the correct time zoned Date.

My guess of what is going on is that the Date() primitive is being overwritten somewhere but I'm unsure of how to check what is overriding it. I am using the date-fns package but that's in terms of date libraries. Below is my package.json

  "dependencies": {
    "@material-ui/core": "^4.12.1",
    "@material-ui/icons": "^4.11.2",
    "@material-ui/lab": "^4.0.0-alpha.60",
    "@mui/x-data-grid": "^5.0.0-beta.7",
    "@testing-library/jest-dom": "^5.13.0",
    "@testing-library/react": "^11.2.7",
    "@testing-library/user-event": "^12.8.3",
    "@types/axios": "^0.14.0",
    "@types/jest": "^26.0.23",
    "@types/lodash": "^4.14.171",
    "@types/material-ui": "^0.21.8",
    "@types/node": "^12.20.14",
    "@types/react": "^17.0.9",
    "@types/react-dom": "^17.0.6",
    "@types/react-helmet": "^6.1.0",
    "@types/serialize-javascript": "^5.0.0",
    "axios": "^0.21.1",
    "clsx": "^1.1.1",
    "d3": "^6.3.1",
    "date-fns": "^2.27.0",
    "date-fns-tz": "^1.1.6",
    "dotenv": "^8.2.0",
    "exponential-backoff": "^3.1.0",
    "gapi-script": "^1.2.0",
    "lodash": "^4.17.21",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-google-login": "^5.2.2",
    "react-helmet": "6.1.0",
    "react-router-dom": "^5.2.0",
    "react-scripts": "4.0.3",
    "rrule": "2.6.8",
    "serialize-javascript": "^5.0.1",
    "typescript": "^4.3.2",
    "web-vitals": "^1.1.2"
  },

Any ideas on how I can fix this issue? Also note that in a previous release of my site, that this was not happening and the current site doesn't have this problem, yet rolling back to the previous version that was running doesn't fix the issue and I have tried on multiple clients.

CodePudding user response:

I found the issue, it was actually because I had a chrome extension installed that would overwrite the Time zone for this specific site on localhost for some reason. The way that it works, was by overriding the Date class. I fixed the issue, by uninstalling/disabling the extension.

Thanks for your help everyone!

  • Related