i don't know if anyone else has this problem. But i've been playing guitar for about 7 years now. And i know im not too bad at it, im currently studying music at university and once i got there i notice i couldnt keep rythm. Its sounds crazy i know but, i can keep a straigt beat but i have trouble finding out where the first beat of a bar is when im improvising. playing by myself i can keep a straigt beat. But maybe its cause i've never played with a band untill last year. i know my teachers told me to play with a metronome it helped a bit. but its still with the first damn beat i keep messing up. what i usually do is improvise a bar and then ill start the next one half a beat short or long. like in 7/8 or 9/8 instead of 4/4. and i have a tendancy to do that alot. half of my composotions are all in 5/8, 7/8, 9/8 or even 19/16 wtf eh! So any advice from anyone would be greatly apreciated. thanks!
The only thing I can think of is to verbally count the beats while you are playing,and obviously practice with a metronome.
I know I'm the third person to recommend a metronome, but you can't hear it enough. People naturally have bad timing, and only extensive practice with a metronome will cure that.

1. Play songs that you already know with a metronome. Try to match the tempo that you already play them at, so there's no change, just an increased focus on timing

2. Play scales and arpeggios you already know, or are learning, with a metronome. Play, say, 8th notes at whatever tempo suits you, and gradually increase it. The *gradual* increase will also help your speed.

3. Play chord progressions with voicings you know/are learning with a metronome.