San Francisco, where it's located

The climate of San Francisco can be defined as "Mediterranean with cool summers". In fact, both the winter temperatures and the rain pattern remind of the Mediterranean climate, but summer is unusually cool because of the cold current that flows along the coast of California and is able to cause fog in San Francisco Bay, and to function as a natural air conditioner for the city and the surrounding areas.
Here are the average temperatures at the Golden Gate Park.
San Francisco - Average temperatures
Min (°C)789911121313131297
Max (°C)131617182022222323211714
Min (°F)454648485254555555544845
Max (°F)556163646872727373706357

However, in the area, there are different microclimates, which must be taken into account by those who plan to move outside of the city proper (for example, you could go to the Yosemite National Park). In general, as you move away from the sea, you will find a more continental climate, a bit colder in winter and much warmer in summer.
Rainfall is not abundant, since it amounts to about 485 millimeters (19 inches) per year, but the period from November to March is quite rainy; in April and October, the rains are quite rare, while from June to September, they are definitely rare and sporadic.
Here is the average precipitation.
San Francisco - Average precipitation

Winter, from December to mid-March, is mild and quite rainy. There are, however, sunny and dry periods, sometimes long. Very cold days are rare: at most, the temperature can approach freezing (0 °C or 32 °F) during the night, and only on colder periods it remains about 8/10 °C (46/50 °F) during the day. However, east of the city, in the Sacramento Valley, and more rarely also to the north and the south of the bay, there may be night frosts.
Snow is an extremely rare phenomenon. On February 5, 1976, it snowed also in the city, where, however, the temperature remained above freezing, and the snow accumulated significantly (13 cm or 5 inches) only on the hills, such as in Twin Peaks.
Every so often, fog can form in the city, while this phenomenon is more common in the Sacramento Valley.

Spring, from mid-March to May, is cool or slightly cold at night, while the days become gradually milder, and sometimes pleasantly warm, though with a moderate breeze in the afternoon that lowers the temperature. The rains become increasingly rarer.

Summer, from June to September, is cool, and it is usually foggy in the morning and sunny in the afternoon, with a cool breeze blowing from the sea. September, albeit slightly, is the warmest month. The foggiest districts (and also the windiest in the afternoon) are the westernmost ones (see Sunset District). The rains are rare, especially in July and August, when basically it never rains.
Daytime temperatures from June to September are around 17/19 °C (63/66 °F) in the towns on the Pacific coast (see Half Moon Bay) and in the western districts of San Francisco, around 21/23 °C (70/73 °F) in the eastern districts, 22/24 °C (72/75 °F) in Oakland and Richmond (on the other side of the bay), 25/26 °C (77/79 °F) in the towns on the south shore of the bay (see Palo Alto, Mountain View), and up to 28 °C (82 °F) in San Jose, just south of the bay.
Beware though: it's sufficient to move to the east, in the Sacramento Valley (see Sacramento, Stockton, Modesto), to find very high temperatures, usually about 33/35 °C (91/95 °F), and sometimes even above 40 °C (104 °F).
In the following map, we can see the average maximum temperatures of August, which shows the significant differences that occur in the area. The city of San Francisco is indicated by a red star.

Average maximum temperatures in the San Francisco area in August (Celsius and Fahrenheit)

Every so often, however, hot air from the desert manages to reach the city, so much so that the temperature can reach 35/38 °C (95/100 °F) from May to October. Anyway, these periods of hot weather are very rare (in fact, they may even not occur for a whole year), they do not last long (just one or two days), and the heat is felt only during the day, while it is cooled by the ocean breeze during the evening. For example, in June 14, 2000, the temperature reached 40.6 °C (105.1 °F), but the minimum temperature of the previous night had been 13 °C (55.5 °F), and that of the next night was only 16 °C (61 °F).

Autumn, in October and November, is initially mild, and gradually becomes cooler and rainier. Usually, it begins to get a little cold at night by late October.

San Francisco

The amount of sunshine in San Francisco is acceptable in winter, when there is a moderate amount of sunny days, but also cloudy periods. In spring, sunny days already prevail, while in summer, it's usually sunny in the afternoon, but in the morning, fogs and mists frequently occur. There are around 3,000 hours of sunshine a year.
San Francisco - Sunshine

Owing to the cold current, the sea in San Francisco is cold all year round. In addition, the water temperature remains quite stable, in fact, it ranges from 12 °C (54 °F) between January and June to 14 °C (57 °F) between August and November. Here are the average sea temperatures.
San Francisco - Sea temperature
Temp (°C)121212121212131414141413
Temp (°F)545454545454555757575755

Best Time

The best time to visit San Francisco is the summer, from June to September, since it is the driest and warmest season of the year. However, you have to take into account cool temperatures, and sometimes even a little cold, at night and in the early morning, as well as morning fogs, so it's better to bring a jacket and a sweater.
Usually, in the months of April, May and October, the weather is good as well, in fact, it's often mild and sunny, even though there's a greater chance of rain; in addition, it can be cold at night, especially in April. Moreover, in spring, afternoon breezes are quite intense.