Almost every guitar player faces this question. Strings are the vocal chords of your guitar and it is important to make sure that they sound their best.
There is no specific answer to this question that applies to all guitars because there are so any factors that influence how your guitar sounds. There are also many different needs that a guitarists have.
Beginner guitarists should mainly look for signs of grit and grime on their guitar, and should listen to see if the sting goes out of tune when playing certain frets. At this point the string is fairly old and definitely needs to be replaced.
If you rarely play, you will be able to get away with not having to change your string more than once or twice a year.
Players who actually perform in front of people should be a little more aware of how their strings actually sound. After about a month, most strings start to sound a little more dull than when they are "fresh."
You'll immediately hear the difference when you change your strings. New strings will sound much brighter and will ring out longer as well. You should change your strings every few months to every month depending on how much you play.
Professionals normally use a preventative measure when playing. In other words, they change their strings all of the time. Some will change their strings before every show or every couple of shows.
It's always a good idea to change them before any studio recording as well to ensure you get the best sound out of them. However, its important to gently stretch your strings and ideally give your strings some time to "set." Otherwise, your strings will stretch as you play and will go flat.
It's best to restring, stretch the strings, and then let your stings "set" over night. Tune up in the morning, and you should be good to go.