This is easily the hardest thing to do and is one thing that comes with maturity. Playing on time helps you make your musical ideas more believable. Even if your playing is not great, if you can deliver great timing, your sound would be a lot better.
Use Metronome / Drum Machine
Number one tip is practice on a metronome or drum machine. Practicing on a metronome is what classical players often do. I have a classical background so I’ve done that a lot, but when I found out about drum machines and drum loops, I started to practising on beats which is lot more fun, a lot less boring, and lot more useful. The main problem is rushing. Please, try not to rush. Playing on time is a matter of respiration and just being calm. When you have something to say, you don’t want rush it just because you know what to say.
Instead, measure what you are saying, and deliberate at the right time. Think about what you are going to play in advance and then wait for beat to come, and try to play along with it. Try to practice how to play a little bit on top of the beat, and little bit behind the beats. That practice inform you on how to deliver your musical phrases or your chords in a much more assertive and decisive way. Just relax, breath, think of what you are going to play, and deliver it on time.
Tip number two is record yourself. Just use the dictaphone if you are playing piano, guitar, bass or even singing. Record yourself while you are practicing your timing. That will inform you what’s going on. If you practice long enough, at some point, you will know whether you grooving along with time or not.