From my experience, it could happen in either case mentioned (on a hot day with the car sitting in the sun, or trying to start it just after having turned off the car). Next time your car won't start, try listening for the clicks and/or the fuel pump (it helps if you have heard what these sound like when your car is working fine).