The only way to do this is to use a time standard independent of the mains frequency. This is usually done with a crystal oscillator which has been used in watches for years since they don't connect to mains power. These oscillators are more stable thenthan the mains frequency over short periods but will eventually drift significantly over long periods (months to years depending on the quality of the crystal). You can also use the time signals transmitted by several different national laboratories (US, Germany, Japan, China) which rely on atomic clocks. These will not have any drift with time. Many low cost clocks are available with this feature.