Therefor I used clock() in front and after an fgets()call. When running on my Windows computer it worked perfectly. However when running on my friends Mac-Book and Linux-PC it gave extremely small results (a few micro seconds of time only).
Now my question is why there is such a difference in implementation of clock() on these OS. For windows it seems like the clock keeps ticking while the thread is sleeping/waiting but for Linux and Mac isn't?
However, we have opted to avoid reimplementing clock() in such a way that it might return time values advancing faster than one second per physical second, as this change would silently break programs depending on the previous behavior (and we expect there are many such programs).
If we look at the source code for clock() on Mac OS X, we see that it is implemented using getrusage, and reads ru_utime + ru_stime. These two fields measure CPU time used by the process (or by the system, on behalf of the process). This means that if usleep (or fgets) causes the OS to swap in a different program for execution until something happens, then any amount of real time (also called "wall time", as in "wall clock") elapsed does not count against the value that clock() returns on Mac OS X. You could probably dig in and find something similar in Linux.
On Linux, you should read time(7). It suggests to use the POSIX 2001 clock_gettime which should exist on recent MacOSX (and on Linux). On Linux, running on not too old hardware (e.g. less than 6 years old laptop or desktop), clock_gettime gives good accuracy, typically dozens of microseconds or better. It gives measures with seconds and nanoseconds (in a struct timespec), but I don't expect the nanosecond figure to be very accurate.
I am having a serious problem with my computer. I simply can't sync the clock on my windows 10 running machine to the internet. When I go to "Date and time settings" and turn the "Set time automatically" switch off and then back on, it either loads extremely long or just immediately displays the wrong time. I searched the internet for so long, but nothing seems to work there. Even when I completely restore my windows, it still wont work. And whats really strange is, that the clock sometimes even runs backwards!
If, like me, your PC is joined to a windows domain then following the steps in sammyg's answer you'll notice at Step 7 that you have no Internet Time tab. You may also have messages in the event viewer from the Time-Service.
I've been having this strange issue with my system clock. Sometimes when I start up Windows 10, my clock displays a time that is 5 hours ahead of the current time. So if it's noon where I live (Eastern time zone), the clock says 5pm. It adjusts for Daylight Savings Time as well staying 5 hours ahead.
I've checked my time zone settings and it's set to the correct time zone. I have internet time set to sync with time.nist.gov, and when manually synchronizing the time, it correctly sets the clock, although the following error message appears when doing so:
This issue started immediately after erasing my hard drive and reinstalling Windows 10 from scratch, so it's not caused by anything I've installed since then. It only happens on Windows startup, but not every time. I currently have Ubuntu 16.04 installed in a dual boot configuration (the problem started before I installed Ubuntu), and I haven't seen any similar issues with the Ubuntu clock.
I've looked through similar time-related issues on the internet, but none seemed to match mine. This question is very similar to my own, but the issue there was caused by the hardware clock being off, and the clock shown in BIOS on my computer is set to the correct time.
UPDATE: It turns out that switching from Ubuntu to Windows triggers the 5 hour offset every time, so it was indeed an issue with the hardware clock being set to Universal/Local by Ubuntu/Windows, respectively.
I would highly suspect Ubuntu and Windows disagreeing on whether the hwclock is localtime or UTC. The conflict usually comes about because Linux uses the the hwclock set in UTC, while Windows uses the hwclock set to the localtime zone.
If you want your hwclock to show the time in your timezone, then you will need to change linux to not be UTC, which means make linux use localtime. If you are OK with your hwclock (BIOS) to be in UTC, then change windows to be UTC.
The elapsed time since the CRT initialization at the start of the process, measured in CLOCKS_PER_SEC units per second. If the elapsed time is unavailable or has exceeded the maximum positive time that can be recorded as a clock_t type, the function returns the value (clock_t)(-1).
The clock function tells how much wall-clock time has passed since the CRT initialization during process start. This function doesn't strictly conform to ISO C, which specifies net CPU time as the return value. To obtain CPU times, use the Win32 GetProcessTimes function. To determine the elapsed time in seconds, divide the value returned by the clock function by the macro CLOCKS_PER_SEC.
Given enough time, the value returned by clock can exceed the maximum positive value of clock_t. When the process has run longer, the value returned by clock is always (clock_t)(-1), as specified by the ISO C99 standard (7.23.2.1) and ISO C11 standard (7.27.2.1). Microsoft implements clock_t as a long, a signed 32-bit integer, and the CLOCKS_PER_SEC macro is defined as 1000. This macro gives a maximum clock function return value of 2147483.647 seconds, or about 24.8 days. Don't rely on the value returned by clock in processes that have run for longer than this amount of time. You can use the 64-bit time function or the Windows QueryPerformanceCounter function to record process elapsed times of many years.
Fliqlo for Mac/Windows is a clock screensaver that allows you to make your desktop/laptop device screen look like a flip clock. It displays the time with flip animation in large white numerals against a black background. Thanks to its visibility, you can check the time even from a distance.
Fliqlo for iOS/iPadOS is a clock app that allows you to make your mobile device screen look like a flip clock. It displays the time with flip animation in large white numerals against a black background. Thanks to its visibility, you can check the time even from a distance.
Operating systems store and retrieve the time in the hardware clock located on your motherboard so that it can keep track of the time even when the system does not have power. Most operating systems (Linux/Unix/Mac) store the time on the hardware clock as UTC by default, though some systems (notably Microsoft Windows) store the time on the hardware clock as the 'local' time. This causes problems in a dual boot system if both systems view the hardware clock differently.
The advantage of having the hardware clock as UTC is that you don't need to change the hardware clock when moving between timezones or when Daylight Savings Time (DST) begins or ends as UTC does not have DST or timezone offsets.
When this happens on a dual-boot system, it's usually because one operating system thinks the hardware clock tracks local time, while the other operating system thinks the hardware clock tracks UTC.
Instead, the best solution is probably to reconfigure Ubuntu to treat the hardware clock time as local time (then you can leave your Windows configuration, and your hardware clock time, alone).
The /etc/rcS fix did not work on my Win7 / Ubuntu 14.04x64 installation, nor did any fixes through the clock GUI. Because the root of the problem is BIOS time VS UTC time, and Windows is a pain in the butt when it comes to using UTC, I just picked a point on the map that uses UTC+0 (no change between BIOS and UTC time).
As for clock app, I had thought it was an issue with it but i have gone through all the troubleshoot with microsoft and clock app support. Reset the app, uninstalled and reinstalled etc etc and because of this, they have said it is a spotify issue.
Hey there, I have gone through all the trouble shoot with clock app. Have reset all these setitngs, uninstalled & reinstalled. Same as spotify app. All these steps were done with online support with Microsoft, clock app & spotify - which has led me to here
This is not a big problem, just update the system clock and the command will work. However, if the Linux system in question is running inside WSL2 on Windows, then it's not quite as straightforward to fix as it ought to be and you're likely to encounter this error more often than you might expect, especially if you're using nested virtualisation.
Hyper-V is a great virtualisation environment and I've got it running on an old Dell PowerEdge R720xd in my home lab. One of the nice things about Hyper-V is that I can shut down the physical host server (e.g. through the web interface of Windows Admin Center) and it will save the state of any virtual machines which are running. When I start the server again, those same virtual machines will automatically start running again (this is all configurable, of course, but this is how my system is configured). And their system clocks are synchronised with the host machine, which is something that most hypervisors do.
Cutting a long story (slightly) short, I have a Windows 10 virtual machine running inside Hyper-V server. Then I'm running WSL2 inside Docker inside that virtual machine, so we're talking nested virtualisation (I can't be the only one who's thinking, "It's turtles all the way down"). If I turn off my Hyper-V server for any reason then, when I switch it back on and the virtual machines start running again, my Windows 10 VM has the correct system time, but my WSL2 environment (in my case Ubuntu 20.04) doesn't. The clock restarts from whenever I shut it down. To illustrate this point, I powered off my server just over a day ago. When I switched it back on and logged in to my dev machine, I opened Windows Terminal and ran the following command:
dd2b598166