System time is measured by a system clock, which is implemented as a simple count of the number of ticks that have transpired since an arbitrary starting date, called the epoch.
The system clock is implemented as a programmable interval timer (PIT) that periodically interrupts the CPU, which then starts executing a timer interrupt service routine. This routine adds one tick to the system clock (a simple counter) and handles other periodic housekeeping tasks (preemption, etc.) before returning to the task the CPU was executing before the interruption.