A digital clock and an analogue quartz clock are basically exactly the same and work on the same principle- a quartz chip, of the correct size and shape, with the correct currency applied, will create electrical transmission at the rate of 32,768 cycles per second, or 117,640,800 cycles per hour, which fills a capacitor (analogue), or is counted by an accumulator (digital). On a quartz analogue, when the capacitor accumulates the power of 32,768 cycles, it releases the stored energy, and the second hand moves one increment. On a digital, when the accumulator counts 32,768, it records a seconds passage.
An atomic clock works on the same principle, except at a much higher frequency. A mechanical clock actually operates on the same principle, too. Energy is a released from a large spring (the mainspring) or weight (as in a grandfather clock) causing a pendulum or balance wheel to rotate. My Rolex operates at a frequency of 6 balance wheel vibrations per second (21,600 vibrations per hour), a modern Rolex does so at 7 vibrations (28,800 vibrations per hour), and a few watches do so at 10 vibrations per second (36,600).
Therefore all of these devices are set up to record an hour on their set number of vibrations. The more vibrations there are, the less an individual loss effects accuracy. If you tap a mechanical watch, it will lose a vibration or two, in order to protect its internals from the shock of the impact.
Here's the thing: If the balance spring is improperly adjusted so it doesn't work at its precise vibration number, if the quartz chip is the wrong size, the current applied is slightly off, it will count the seconds too fast or too slow, because it will take the wrong amount of time for each vibration, and so it counts the time wrong. Digital clocks are nearly 100% precise- that is to say, if they are working anything near properly, each vibration will take exactly the same amount of time, each counted second will take exactly the same amount of time. But that does not mean that they are accurate- that is to say, that does not mean that each precisely measured interval of 32,768 vibrations takes a precise second.