But usually the OS e.g: Raspbian has the NTP package installed. If it's connected to Internet, the daemon software ntpd would update the time on Pi automatically for you.
However if there is no internet, at least Raspbian has the fake-hwclock package installed by default. This package will remember the time when you shut down the device. So the Pi's time would lag for the period which it is not running.
To solve the offline time lag problem, there are some tiny RTC hardwares support Raspberry Pi and cost about 4 bucks around. I haven't tried any, but it might be a good idea to maintain an accurate time for Raspberry Pi.