How does my computer know what time it is?
Every time I turn on my computer it knows exactly the right time. How does it keep track even when the computer is off?
Most computers actually contain what is essentially a miniature Quartz watch inside them that is powered by the CMOS battery. This is evident in the BIOS (or UEFI in more modern computers) since the clock still ticks without the network. Without power, it continues to tick due to the CMOS battery, again evident by booting into the BIOS/UEFI. When you do end up getting internet, it'll recalibrate itself with a server, all the while with the miniature Quartz watch still ticking.
Computers have a low-power internal clock that runs when the machine is powered off. It's called a CMOS clock. It essentially uses the same amount of power as a wrist watch and stores that in a low-power memory chip and updates your machine when it powers back on. Then, when your computer gets the actual time from a server of from some other command, it updates the CMOS chip so that it can remember the current time the next time it's turned off.