The best times of year to visit both cities are spring and fall, particularly March-May and September-November. Beijing’s winters are cruel, with temperatures dropping as low as -10 degrees Fahrenheit. However, if you can bear the cold, it’s worth traveling during winter for the clear skies, mild white sunshine, and crisp air. As soon as the warmer months come, so does the worst of the pollution.
Summers are hot and damp, with 60 percent of annual rainfall coming in July and August. Shanghai is a humid furnace between late June and late September, so avoid summer if at all possible. The “plum rains” fall in early- to mid-June, following a pleasant couple of months of springtime. Fall is warm and dry.
Avoid late January to early February if you don’t want to get caught up in the Chinese New Year festivities [1] that render many attractions closed. Travel between cities at this time of year is a nightmare, as tens of millions of people are on the move. The holiday is a moveable feast (meaning the dates change each year), so check dates before you book your trip. Similarly, the Golden Week holiday in the first week of October sees chaotic transportation and overcrowded tourist attractions.
Links:
[1] http://www.moon.com/destinations/beijing-shanghai/beijing-arts-and-leisure/chinese-new-year-and-lantern-festival