How to Fix Apt Packages Release File for XY Is Not Valid Yet

As I tried to update my WSL (Windows Subsystem for Linux) installation, I run into this error message:

sudo apt-get update

E: Release file for https://security.ubuntu.com/ubuntu/dists/jammy-security/InRelease is not valid yet (invalid for another 58min 27s). Updates for this repository will not be applied.

How could that be? The difference of nearly an hour got me thinking about a wrong system clock, but on Windows everything was correct. As I checked the date inside WSL, it was indeed way off (at 15:48):

date

Mon Jan 1 14:16:03 CET 2024

Since the hardware clock (as shown in Windows) was correct, I could fix the time inside WSL by setting the system clock to the value of the hardware clock:

sudo hwclock --hctosys

The date util now returned the correct time:

date

Mon Jan 1 15:49:05 CET 2024

And with the fixed clock I could run apt-get update without any strange error messages.