-
Notifications
You must be signed in to change notification settings - Fork 822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
system date is not same with windows (WSL 2) #4245
Comments
Which distro are you using? Any errors in dmesg? WSL relies on the tzdata package to do the translation. |
it's ubuntu 18.04 Thanks. |
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. |
This is what i see in dmesg related to system time. I'm using the Ubuntu 18.04 WSL 2. |
Me too. |
This is the error message I got when I run |
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.
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 CREDIT: I was having trouble with the returned time format. The script above is a barely modified version from here |
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
|
I would venture using chrony would be a better option than ntp. Or even ntpsec. Just add something similar such as However that said, a simple PR to enable |
Can confirm. This is a very serious bug, which means any date/time related service would be unreliable in WSL2... including apt. |
Can confirm this as well. On converted distro's and newly downloaded ones. This makes it impossible to download newer packages from |
Quick fix! In PowerShell or Command Prompt:
Next time you start a WSL session, it'll be a cold boot and the time will be correct. |
We are working on a fix, in the meantime "sudo hwclock -s" should get things working. |
just a quick and concrete example of when it happened for me:
I went the |
Glad i found this post. This was annoying me for awhile, FYI this also affects azure command line due to bad timestamp. This works for me:
Below is the error message from az cli in case someone is searching. The error is misleading, but the root cause is that the CLI is using an outdated sys time from WSL2. You do not have the required permissions needed to perform this operation. |
I had this exactly same problem back on the time that I was using VirtualBox for virtualization, every time my host machine go to sleep. The virtual machine stopped the clock on that time. But when the host come back from sleep, the virtual machine does not look at the time on host machine to update the clock. This simple continue counting the time from where it had stopped. Exactly the same bug again but now on WSL 2 Virtualization. |
I have a slightly different issue. I have powershell and WSL 2 windows up and running side by side. Print the date/time on powershell first then WSL 2, and notice WSL 2 is always slightly behind
I tried restarting WSL2 in powershell, it'll fix the issue temporary, but will eventually be off again. Anyone else run into this issue? Is this related to the clock being out of sync with the host? |
This should be much better in build 18970. |
@benhillis I thought pausing/unpausing a VM would be the equivalent to sleep a PC but I guess I was wrong. Would it be possible to implement a similar fix when pausing/unpausing a VM? |
What's the relation between pause/resume of a VM with this issue which is fixed now? |
@Biswa96 It's the same problem. If you pause a VM in Hyper-V Manager for some time then after unpausing it system date is not the same and edit:added "Manager" in order to avoid confusion |
@onomatopellan - Looks like this fix doesn't work with nested, investigating... |
Please all, use the simple and quick fix as mentioned before as long as this issue is not fixed:
|
@danwhitston it's enough to shutdown the VM with |
Thanks both. You're right, chronyd must have been hitting the skew limit, given WSL's time was out by days rather than milliseconds. |
Why is this issue closed? It has the label "fixedinreleasebuild", but does not seem fixed in the latest public release or any updates... |
@janfrederik This issue was actually fixed. If you still have time sync problems follow #5324 issue instead. |
That's funny, I had an incorrect date in WSL on waking my laptop today. |
|
I have found this issues because this still happens. I was actually writing a topic about the |
This is not fixed. I reset my clock every day. |
This is not fixed. I just keep using the |
I can't believe this is still broken. Debating about implementing some kind of hack to mitigate it, but in the meantime I just run |
Just ran into this same problem. Why this issue is marked as closed is beyond me. |
There's another issue on this topic at #5324, still open since it is not fixed yet. |
To me, it does not seem to occur as of Windows 20H2 update. However, because it is not listed in the resolved issues in Windows 10 version 20H2, I am unsure of why it does not recur after the update. EDIT: It's still recurring. |
I also have this problem. The time reported by Windows appears accurate, seems to match "time.io" for example. |
Is there a solution if
|
Yes, I also get that error. So using
Of course I realise that you need to run it as
|
I was already root. I exec into a redis docker container: |
Open a bash shell directly from Windows, then try "sudo hwclock -s". That runs but still left me a few seconds behind though. |
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. |
prod was broken. solution was do delete windows and install unix system |
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? |
Bump? |
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. |
Experiencing the same issue, this did not work for me
this works for some time but then the time resets again
|
If you have a Docker container, don't try changing time within the container. Instead, change the server time with:
`# ~/set-date.sh Get time from a reliable sourceTIME_FROM_SERVER=$(curl -v --insecure --silent https://google.com/ 2>&1 | grep Date | sed -e 's/< Date: //'); set stored date and timedate +"%d%m%Y%H%M%S" -d "$TIME_FROM_SERVER"; echo "Time updated with success!";` |
Hey, I hope this can help :) so, run |
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. |
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.
The text was updated successfully, but these errors were encountered: