You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
system date is not same with windows (WSL 2) #4245
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.
Reacted by Ahmed ElSayed, Rodrigo Boratto, Yun Zhi Lin, Van Gorden, Kip Obenauf, pvnguyen123, William Perron, Victor Villas, François-Xavier Gsell, Vineeth Pillai and 73 more
[ 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.
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.
Reacted by Changsheng Wu, Denis Olsem, Charlie Chen, The Coding Dreamer and Amir Szekely
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.
Get time from reliable source on the internet using Curl.
Parse time and set it onto the WSL linux instance
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
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
Reacted by Victor Villas, Flynn, Lukas Juhrich, 4ft35t, EmmanuelPowster, Matheus Toniolli, David DIVERRES, Octávio Richter, Martins Barinskis, Opher Vishnia and 54 more
Reacted by Flynn, Anton Teykhrib, umeyuki, Nikita Turkin, rswe, Ruslan Khasanbaev, Matheus Poli, Justin VanWinkle, wildflower, Daniel Cohen Hillel and 7 more
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.
Reacted by Michael Orlov, Aleksandr Nedorezov, Franek Stark and Derek
Can confirm. This is a very serious bug, which means any date/time related service would be unreliable in WSL2... including apt.
Reacted by Kip Obenauf, pvnguyen123, motiregev, Lucius Gaitán, Sean McCarthy, Jean-Francois Levesque, Jake Cherrie, Andy Jordan, Anton Melser, Du Toit Minnaar and 12 more
Next time you start a WSL session, it'll be a cold boot and the time will be correct.
Reacted by Nicholas Dille, Kirill Popolov, William Perron, Julian, Kai Richardson, Ralf Kretzschmar, Chase 李, Opher Vishnia, Bhoom Suktitipat, 4x0v7 and 35 more
Reacted by Alfan Nur Fauzan and Ishwar Jagdale
Reacted by PaulaADiazSilva, Maki Kato, WangSen, Mathias Parodi, Alfan Nur Fauzan and Ishwar Jagdale
We are working on a fix, in the meantime "sudo hwclock -s" should get things working.
Reacted by WSLUser, cxsy, inomoto, toberoni, Radu Matei, Van Gorden, Max Liebkies, Rhahkeem, Kip Obenauf, Apostolos Tsakpinis and 142 more
Reacted by Kevin Bosman, Chris Nesbit and tyongguang
Reacted by Pablo Wolochwianski, Carlton Gibson, Kai Richardson, Joe Maller, Chris Otto, Bernard, Kevin Xiang Li, Parker McMullin, Luo Chen, Niranjan and 4 more
Reacted by Joe Maller, Bernard, Kevin Xiang Li, Parker McMullin, Andy Jordan, studyxiao, Niranjan, Felipe Alvarez, Allan Targino, Maki Kato and 2 more
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.
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
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.
Reacted by blacksheepaul, Antonio Marcedone, Irina Nikolaeva, Antonio Gurgel, Igor Rendulic, Kyle P, Lamarth, mvarendorff, Leon Visscher, Sérgio Rebelo and 1 more
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?
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.
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.
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
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.
Activity
[-]system date is not same with windows[/-][+]system date is not same with windows (WSL 2)[/+]benhillis commentedon Jun 29, 2019
Which distro are you using? Any errors in dmesg? WSL relies on the tzdata package to do the translation.
erdemece commentedon Jun 29, 2019
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.
radu-matei commentedon Jun 30, 2019
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.
joeljwilliams commentedon Jun 30, 2019
This is what i see in dmesg related to system time. I'm using the Ubuntu 18.04 WSL 2.
lmatter commentedon Jul 2, 2019
Me too.
cxsy commentedon Jul 2, 2019
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.
ngasst commentedon Jul 2, 2019
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:
After you run this, you should see the current timestamp printed as well as the success message.
Then, in your
bashrc,zshrcor equivalent, call the scriptsh ~/set-date.shCREDIT: I was having trouble with the returned time format. The script above is a barely modified version from here
MiklerGM commentedon Jul 3, 2019
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
ntpdatefor time sync purposes.WSLUser commentedon Jul 3, 2019
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 ibursttochrony.conf(orntp.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.peidaqi commentedon Jul 7, 2019
Can confirm. This is a very serious bug, which means any date/time related service would be unreliable in WSL2... including apt.
Rhahkeem commentedon Jul 7, 2019
Can confirm this as well. On converted distro's and newly downloaded ones. This makes it impossible to download newer packages from
aptjdub commentedon Jul 9, 2019
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.
benhillis commentedon Jul 10, 2019
We are working on a fix, in the meantime "sudo hwclock -s" should get things working.
nunix commentedon Jul 23, 2019
just a quick and concrete example of when it happened for me:
I went the
wsl --shutdownroute and it worked. Will do thehwclocknext time 👍115 remaining items
tomqwpl commentedon Dec 3, 2020
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 -scommand makes no difference for me, the time within WSL2 is unchanged. Restarting wsl withwsl --shutdownhas made the clocks synchronize though.tomqwpl commentedon Dec 3, 2020
Yes, I also get that error. So using
hwclock -son its own produces no output to say its failed, but--versoseproduces:Of course I realise that you need to run it as
sudo hwclock -sand that then does work (for me):Mereep commentedon Dec 7, 2020
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.
jurij commentedon Dec 16, 2020
prod was broken. solution was do delete windows and install unix system
davystrong commentedon Dec 28, 2020
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?
arcs- commentedon Jan 4, 2021
Bump?
tomqwpl commentedon Jan 4, 2021
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.
pauljfx commentedon Jan 5, 2021
Experiencing the same issue, this did not work for me
this works for some time but then the time resets again
RoyPour commentedon Jan 14, 2021
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.
`# ~/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!";`
OscBacon commentedon Jan 30, 2021
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.comsjschultze commentedon Feb 5, 2021
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.