From the StackExchange FAQ:
- Don't hesitate to accept an answer that is well-written, suggests a good practice and works for you.
- Otherwise, even if there are answers that are good enough but that you're not entirely satisfied by, you might wait 24 to 48 hours to give other people a chance to give you a better answer. A question with an accepted answer isn't as likely to receive further attention as one without an accepted answer.
So, the SE recommendation is: if you're completely satisfied with an answer, accept it immediately. If you're mostly satisfied with an answer, accept it within a couple of days.
(Note that you can change your accepted answer if a better one comes along later.)
This is only a recommendation; you can accept an answer immediately, years later, not at all, etc. if that's what you want to do.