Computer Science Stack Exchange is a question and answer site for students, researchers and practitioners of computer science. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How are computers able to tell the exactly correct time and date every time?

Whenever I close the computer (shut it down) all connections and processes inside stop. How is it that when I open the computer again it tells the exact correct time? Does the computer not shut down completely when I shut it down? Are there some processes still running in it? But then how does my laptop tell the correct time when I take out the battery (and thus forcibly stop all processes) and start it again after a few days?

share|cite|improve this question
1  
Is this question really on topic for this site? It seems more appropriate for Super User to me. – Ilmari Karonen Mar 28 at 13:34
1  
@IlmariKaronen This does seem to count as question about "computer architecture", if I am understanding the term correctly. – PyRulez Mar 29 at 2:09
up vote 62 down vote accepted

Computers have a "real-time clock" -- a special hardware device (e.g., containing a quartz crystal) on the motherboard that maintains the time. It is always powered, even when you shut your computer off. Also, the motherboard has a small battery that is used to power the clock device even when you disconnect your computer from power. The battery doesn't last forever, but it will last at least a few weeks. This helps the computer keep track of the time even when your computer is shut off. The real-time clock doesn't need much power, so it's not wasting energy. If you take out the clock battery in addition to removing the main battery and disconnecting the power cable then the computer will lose track of time and will ask you to enter the time and date when you restart the computer.

To learn more, see Real-time clock and CMOS battery and Why does my motherboard have a battery.

Also, on many computers, when you connect your computer to an Internet connection, the OS will go find a time server on the network and query the time server for the current time. The OS can use this to very accurately set your computer's local clock. This uses the Network Time Protocol, also called NTP.

share|cite|improve this answer
1  
Can an OS set the BIOS time? What I mean is, if I forcibly reset the hardware clock, then boot and connect to NTP or set the clock myself, will the BIOS recognise this? – cat Mar 26 at 0:54
1  
Yes. Changing the OS's system time sets the real time clock a.k.a. the BIOS time. Internally the clock is just counting the number of seconds (or milliseconds) since the Epoch (usually January 1, 1970 00:00), so it's not doing much work and can be powered by a coin size battery for years. Higher level functions in the OS do the job of converting that count to a date/time to display. – Chris Nava Mar 26 at 3:38
    
The quartz crystal is not the special hardware device that keeps track of time (although it's one component). – immibis Mar 26 at 5:32
1  
@tatan no, the phone is powered all that time by its battery. It's mostly the same as you are able to turn on your PC by pressing its power button when the PC is supposed to have been shut down (but not disconnected from wall socket). – Ruslan Mar 26 at 19:00
1  
I'd rephrase the last paragraph, changing computers to OSs. Any PC that connects to Internet might not to, and vice versa - it is OS job to do this, not PCs(implying hardware). – MatthewRock Mar 26 at 20:54

If you remove the battery on the motherboard then the computer wouldn't have any way to tell the time.

This is also the case with mobile phones. If you let a phone discharge and then not recharge it for more than a few weeks it will also "forget the time" because the small auxiliary battery is discharged completely and nothing is powering on the real-time clock.

You could try to power on an old mobile phone if you have one and check it yourself to see that it "forgot the time".

This is how the battery looks. https://yandex.com/images/touch/search?text=mobo%20battery&source=tabbar

I had to buy one a few times when mine started to last less then a day. I had to configure the clock everytime i turned on the PC.

share|cite|improve this answer
2  
Many operating systems now use NTP (Network Time Protocol) and can use that to reset themselves automatically on startup, so they don't actually need the built in clock. – James Snell Mar 27 at 19:49
2  
@JamesSnell That will however mess up time stamps in logfiles as well as any file modified during boot before NTP is started. – kasperd Mar 28 at 11:39
    
@kasperd - timestamps really aren't as important as they used to be as many systems use other metadata (versioning). Look at boot logs from systems which lack a RTC like routers or the raspberry pi and they log when the time was updated (and what to). It might be more important in disconnected systems, but that's becoming less important over time. – James Snell Mar 28 at 12:47
1  
@JamesSnell I have several single board computers capable of running a standard x86 operating system, but they lack a battery backed RTC. In the end I had them run an absolute minimal network stack from within a ramdisk in order to run `ntpdate' before any disk access would take place. – kasperd Mar 28 at 13:09
    
@JamesSnell Yes but laptops and tablets connect to wifi after they boot (at least most of them do that) and they do not have ethernet connection, so battery is still in use in almost all computers. Also desktop computers do not have internet all the time either. Some people close their routers at night or just do not use internet all the time if they want to play games or watch a movie and don't turn the router on. Not everyone wants to be connected to internet all the time. – yoyo_fun Apr 15 at 10:41

When you start Windows, it gains direct access to the memory of the Real Time Clock (RTC) and uses its date and time values to set the computer date and time. Timer interrupts maintain the computer time when Windows is running. A Time Daemon in Windows runs approximately once each hour after the Windows starts. The Time Daemon compares the time in Windows with the time in the RTC. If the two times are more than one minute apart, Windows changes the time and date to match the RTC. You cannot change the time interval for the Time Daemon to run.

If you use a time synchronizing service, such as the TimeServ.exe tool included with the Windows NT 4.0 Resource Kit, the tool updates the time in Windows and the computer's RTC. If the Windows Time Service runs on a Windows 2000 based-computer, the Time Daemon in Windows cannot run approximately one time each hour after the Windows starts.

For more details visit this link:http://msdn2.microsoft.com/en-us/library/ms724936.aspxhttp://msdn2.microsoft.com/en-us/library/ms724942.aspx

share|cite|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.