You can apply for a visa up to 3 months before your date of travel to the UK. UKVI say that you should get a decision on your visa within 3 weeks, however some may take longer.
Please check this guide to find out how long getting a visa might take in the country you’re applying from the following website: guide processing times