Prophet Muhammad (PBUH) said: “if you were to intentionally commit a sin immediately follow it up with a good deed.” When we commit sins, we shouldn’t think it is a bad time to ask Allah for forgiveness.
There is no such thing as a bad time to ask Allah for anything. There is no such a thing as a bad time to make dhikr of Allah even if you are in the middle of a sin. When you are committing a sin that it is when you need the dhikr of Allah.
When you have committed a sin, immediately follow it up with a good deed. Any good deed will wipe it away!
The best of the good deeds is saying La ilaha illAllah. Nothing is better than saying this! The most beloved deeds to Allah are the obligations. At the top of the list of obligations is At-Tawheed. So when you commit a sin, say la ilaha illAllah!