Why is time important for 2FA codes?
2FA codes are generated randomly every 30 seconds, if the site and the mobile app weren't in sync, then the codes will not work since every 30 seconds the code expires.
One important thing is to make sure that your mobile date & time are correct and up to date.
Google Authenticator - Time correction for codes:
Google authenticator app has the option to sync time for codes, if you are typing the code several times into the site before the code time expires, and you still getting the error "Invalid OTP" and you are using the google authenticator app then this guide might be useful for you.
Step 1. Click on the menu
Step 2. Click on "Settings"
Step 3. Click on "Time correction for codes"
Step 4. Click on "Sync now"
Once you complete this step then you will get one of either messages:
Time already correct
Time updated for codes