Skip to content

system date is not same with windows (WSL 2) #4245

Closed

Description

@erdemece
  • Your Windows build number: 18922

  • date is updating itself in WSL 2 even I set the timezone and change date manually with date command

  • because the date is wrong I can't sudo apt update and I have to set the date to my local time everytime I open WSL 2

thanks.

Activity

  1. changed the title [-]system date is not same with windows[/-] [+]system date is not same with windows (WSL 2)[/+] on Jun 29, 2019
  2. benhillis commented on Jun 29, 2019

    @benhillis
    Member

    Which distro are you using? Any errors in dmesg? WSL relies on the tzdata package to do the translation.

  3. erdemece commented on Jun 29, 2019

    @erdemece
    Author

    Which distro are you using? Any errors in dmesg? WSL relies on the tzdata package to do the translation.

    it's ubuntu 18.04
    well I just converted from WSL 2 to WSL 1. I will reply after I convert WSL 2 with the outputs.

    Thanks.

  4. radu-matei commented on Jun 30, 2019

    @radu-matei

    I can also confirm this, and it’s especially bad when changing time zones, leading up to not being able to use a package manager at all.

  5. joeljwilliams commented on Jun 30, 2019

    @joeljwilliams
    [    0.335041] rtc_cmos 00:00: setting system clock to 2019-06-21 22:54:24 UTC (1561157664)
    [    0.335057] Unstable clock detected, switching default tracing clock to "global"
                   If you want to keep using the local clock, then add:
                     "trace_clock=local"
                   on the kernel command line
    

    This is what i see in dmesg related to system time. I'm using the Ubuntu 18.04 WSL 2.

  6. lmatter commented on Jul 2, 2019

    @lmatter

    Me too.

  7. cxsy commented on Jul 2, 2019

    @cxsy
    E: Release file for http://security.ubuntu.com/ubuntu/dists/bionic-security/InRelease is not valid yet (invalid for another 14h 47min 54s). Updates for this repository will not be applied.
    E: Release file for http://archive.ubuntu.com/ubuntu/dists/bionic-updates/InRelease is not valid yet (invalid for another 15h 2min 9s). Updates for this repository will not be applied.
    E: Release file for http://archive.ubuntu.com/ubuntu/dists/bionic-backports/InRelease is not valid yet (invalid for another 14h 49min 15s). Updates for this repository will not be applied.
    

    This is the error message I got when I run sudo apt update. I think it's related to the wrong system date.
    One workaround is switch to WSL1 and then switch back.

  8. ngasst commented on Jul 2, 2019

    @ngasst

    I was having the same issue, but my main gripe was that it was preventing me from reliably working with docker containers in what was otherwise a very workable setup.

    Here's my solution along with necessary code snippet.

    1. Get time from reliable source on the internet using Curl.
    2. Parse time and set it onto the WSL linux instance
    3. Create a shell script and modify .rc file to run said script at start

    Script:

    # ~/set-date.sh
    
    # Get time from google server or some other reliable source
    TIME_FROM_SERVER=$(curl -v --insecure --silent https://google.com/ 2>&1 | grep Date | sed -e 's/< Date: //');
    
    # Set stored time
    date +"%d%m%Y%H%M%S" -d "$TIME_FROM_SERVER";
    
    echo "Time updated with success!";

    After you run this, you should see the current timestamp printed as well as the success message.

    Then, in your bashrc, zshrc or equivalent, call the script
    sh ~/set-date.sh

    CREDIT: I was having trouble with the returned time format. The script above is a barely modified version from here

  9. MiklerGM commented on Jul 3, 2019

    @MiklerGM

    The problem with the date begins when I put my notebook at sleep, the system clock is ticking but not the WSL one. It can be easily reproduced.

    I've been using ntpdate for time sync purposes.

    sudo ntpdate pool.ntp.org
    
  10. WSLUser commented on Jul 3, 2019

    @WSLUser

    I would venture using chrony would be a better option than ntp. Or even ntpsec. Just add something similar such as pool 2.fedora.pool.ntp.org iburstto chrony.conf (or ntp.conf). If you have a local NTP server serving up time for all your machines, point there (and please have 2 servers configured. Yes one will work, but it is very bad practice).

    However that said, a simple PR to enable "trace_clock=local" in the WSL2 repo should be made.

  11. peidaqi commented on Jul 7, 2019

    @peidaqi

    Can confirm. This is a very serious bug, which means any date/time related service would be unreliable in WSL2... including apt.

  12. Rhahkeem commented on Jul 7, 2019

    @Rhahkeem

    Can confirm this as well. On converted distro's and newly downloaded ones. This makes it impossible to download newer packages from apt

  13. jdub commented on Jul 9, 2019

    @jdub

    Quick fix! In PowerShell or Command Prompt:

    wsl --shutdown
    

    Next time you start a WSL session, it'll be a cold boot and the time will be correct.

  14. benhillis commented on Jul 10, 2019

    @benhillis
    Member

    We are working on a fix, in the meantime "sudo hwclock -s" should get things working.

  15. nunix commented on Jul 23, 2019

    @nunix

    just a quick and concrete example of when it happened for me:

    • started a WSL2 distro
    • made the laptop sleep
    • started again the laptop the next day
    • checked the date/time -> was still set to the day before

    I went the wsl --shutdown route and it worked. Will do the hwclock next time 👍

  16. 115 remaining items

  17. tomqwpl commented on Dec 3, 2020

    @tomqwpl

    I also have this problem. The time reported by Windows appears accurate, seems to match "time.io" for example.
    The time reported within WSL2 is about 25 seconds ahead.
    The sudo hwclock -s command makes no difference for me, the time within WSL2 is unchanged. Restarting wsl with wsl --shutdown has made the clocks synchronize though.

  18. tomqwpl commented on Dec 3, 2020

    @tomqwpl

    Yes, I also get that error. So using hwclock -s on its own produces no output to say its failed, but --versose produces:

    hwclock from util-linux 2.34
    System Time: 1607018493.397590
    Trying to open: /dev/rtc0
    No usable clock interface found.
    hwclock: Cannot access the Hardware Clock via any known method.
    

    Of course I realise that you need to run it as sudo hwclock -s and that then does work (for me):

    hwclock from util-linux 2.34
    System Time: 1607018597.374906
    Trying to open: /dev/rtc0
    Using the rtc interface to the clock.
    Assuming hardware clock is kept in UTC time.
    Waiting for clock tick...
    ...got clock tick
    Time read from Hardware Clock: 2020/12/03 18:03:18
    Hw clock time : 2020/12/03 18:03:18 = 1607018598 seconds since 1969
    Time since last adjustment is 1607018598 seconds
    Calculated Hardware Clock drift is 0.000000 seconds
    2020-12-03 18:03:16.947133+00:00
    
  19. Mereep commented on Dec 7, 2020

    @Mereep

    Same problem. It is December '20. The bug is from June '19.

    This thing is serious since Docker is using WSL 2 now, effectively having wrong clocks in all containers.

  20. jurij commented on Dec 16, 2020

    @jurij

    prod was broken. solution was do delete windows and install unix system

  21. davystrong commented on Dec 28, 2020

    @davystrong

    Just after spending a whole day trying to work out why a Docker container was getting 403 when connecting to AWS... then checked the date! Very annoying. Why has this issue been closed?

  22. arcs- commented on Jan 4, 2021

    @arcs-

    Bump?

  23. tomqwpl commented on Jan 4, 2021

    @tomqwpl

    Docker containers having the wrong clock (which is the effect of this issue) is a serious problem. The reason I ran into this was that I have a docker container running a service that is issuing authentication tokens for a web service. Trouble is that you authenticate and get a token, but when you use the token the receiver (not running in docker, and hence having a different clock) complains that the token is being used before it's issued because the clocks aren't in sync. This is just one example, but there would be many ways in which not having the clocks synched will cause unexpected issues.

  24. pauljfx commented on Jan 5, 2021

    @pauljfx

    Experiencing the same issue, this did not work for me

    sudo hwclock -s
    

    this works for some time but then the time resets again

    sudo ntpdate pool.ntp.org
    
  25. RoyPour commented on Jan 14, 2021

    @RoyPour

    If you have a Docker container, don't try changing time within the container. Instead, change the server time with:
    sudo ntpdate pool.ntp.org
    (if you don't have it on system then install with: sudo apt-get update & sudo apt-get install ntpdate)
    or
    sudo ~/set-date.sh
    given set-date.sh is defined below.

    • Having correct time becomes a must when you are pushing or pulling updates to Azure blob or any other data factory.

    `# ~/set-date.sh

    Get time from a reliable source

    TIME_FROM_SERVER=$(curl -v --insecure --silent https://google.com/ 2>&1 | grep Date | sed -e 's/< Date: //');

    set stored date and time

    date +"%d%m%Y%H%M%S" -d "$TIME_FROM_SERVER";

    echo "Time updated with success!";`

  26. OscBacon commented on Jan 30, 2021

    @OscBacon

    Hey, I hope this can help :)
    I decided to set up a crontab to update my time every 10 minutes.
    I think that it's a good way to make sure the time doesn't drift too much.
    Note that since you need sudo to run ntpdate, you need to use the sudo crontab:

    so, run sudo crontab -e, then add:
    10 * * * * ntpdate time.windows.com

  27. sjschultze commented on Feb 5, 2021

    @sjschultze

    Folks still commenting on this issue might want to comment on #5324 instead because that one's still open and comments there are probably more likely to get noticed by MSFT than comments on this closed issue.

    I can't believe this bug has existed for this long. Wow.

  28. locked and limited conversation to collaborators on Feb 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

wsl2

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions