The weather is never known for sure and you cannot predict or confirm if the weather on the day of your race would be optimal, very hot, wet and damp, etc. That is why training for extremes will help you dramatically on race day. If you are training in a cool climate for a race in a hot location, layers of clothing to simulate the hot and sweating is a proven technique. A word of caution, do not ever wear rubber suits or anything that is not breathable to accomplish this.
For those of you who have a fairly good idea of the general weather, for instance, if you know you are going to be racing in southern Florida in June, for instance, you can be fairly confident in assuming it is going to be a hot and humid race day. To train for these types of races, a method called acclimatization is smart. A good rule to follow is to give yourself approximately 10-14 days for your body to acclimatize for those muggy conditions. Aerobic workouts in the heat will be a better option and don’t be shocked if your training this way decreases your pace after acclimatization.
For the cold weather, keep a thermos flask with you to have a hot drink in you before your swim so you can keep your body in balance. This will help regulate warmth for when you start the race through the sprint. Layers are important, that cold wind hitting you during your bike ride could be brutal for some, so having a protective jacket to combat it is very useful.
Last, altitude is a huge factor as everyone knows. Give yourself time. Arrive at the altitude you are set to race at minimum 45 hours before the race. Research shows this helps with endurance activities.