Search code examples
google-chromedockertimezoneheadless

'new Date()' gets a wrong timezone from headless chrome in linux docker image


I have a docker image with linux, and there is a headless chrome service. When I use "new Date()" in my html, it get a time "Sat Dec 29 2018 02:45:24 GMT-0600 (Central Standard Time)", it's wrong. The docker time is 'Sat, 29 Dec 2018 17:24:27 +0800', it's right.

And my time zone is 'CST' (China standard Time), as similar as 'CST'(Central Standard Time). Dose that matter?...

enter image description here


Solution

  • Sure, containers are created in UTC timezone by default. How to make it correspond to your host's OS - depends on the type of guest OS. For Debian I simply set

    Dockerfile

    ....
    ENV TZ=Europe/Moscow   # or whatever is you one
    ....