The history of timekeeping devices dates back to when ancient civilizations first observed astronomical bodies as they moved across the sky. Devices and methods for keeping time have since then improved through a long series of new inventions and ideas. Sundials and water clocks originated from ancient Egypt, and were later used by the Babylonians, the Greeks and the Chinese; medieval Islamic water clocks were unrivalled in their sophistication until the mid-14th century. Incense clocks, which may have been invented in India, were being used in China by the 6th century. The hourglass, one of the few reliable methods of measuring time at sea, was a European invention and does not seem to have been used in China before the mid-16th century.
In medieval Europe, purely mechanical clocks were developed after the invention of the bell-striking alarm, used to warn a man to toll the monastic bell. The weight-driven mechanical clock, controlled by the action of a verge and foliot, was a synthesis of earlier ideas derived from European and Islamic science, and one of the most important inventions in the history of the timekeeping. The most famous mechanical clock was designed and built by Henry de Vic in c.1360—for the next 300 years, all the improvements in timekeeping were essentially developments based on it. The invention of the mainspring in the early 15th century allowed small clocks to be built for the first time.
From the 17th century, the discovery that clocks could be controlled by harmonic oscillators led to the most productive era in the history of timekeeping. Leonardo da Vinci had produced the earliest known drawings of a pendulum in 1493–1494, and in 1582 Galileo Galilei had investigated the regular swing of the pendulum, discovering that frequency was only dependent on length. The pendulum clock, designed and built by Dutch polymath Christiaan Huygens in 1656, was so much more accurate than other kinds of mechanical timekeepers that few clocks have survived with their verge and foliot mechanisms intact. Other innovations in timekeeping during this period include inventions for striking clocks, the repeating clock and the deadbeat escapement. Errors in early pendulum clocks were eclipsed by those caused by temperature variation, a problem tackled during the 18th century by the English clockmakers John Harrison and George Graham; only the invention of invar in 1895 eliminated the need for such innovations.
From the 18th century, a succession of innovations and inventions led to timekeeping devices becoming increasingly accurate. Following the Scilly naval disaster of 1707, after which governments offered a prize to anyone who could discover a way to determine longitude, Harrison built a succession of accurate timepieces. The electric clock, invented in 1840, was used to control the most accurate pendulum clocks until the 1940s, when quartz timers became the basis for the precise measurement of time and frequency. The wristwatch, which had been recognised as a valuable military tool during the Boer War, became a symbol of masculinity and bravado after World War I. During the 20th century the non-magnetic wristwatch, battery-driven watches, the quartz wristwatch, and transistors and plastic parts were all invented. The most accurate timekeeping devices in practical use today are atomic clocks, which can be accurate to within a few billionths of a second per year. They are used to calibrate other clocks and timekeeping instruments.