Upvote:2
For the H1B visa, from USTravelDocs:
You can apply for an H1B visa up to 90 days before the petition start date listed on the form I-797, Notice of Action. However, you cannot enter the US earlier than 10 days prior to the start date listed on the I-797 unless you are already working on an H1B visa for the same petitioner.
For the B1/B2, there's no real restriction as far as I can find, the only recommendation is that you apply no later than 60 days before the date of travel to ensure that it gets processed in time. Indeed the USCIS pages on B1 visas and B2 visas mention no requirement for when you can apply.