The short answer
Quote Investigator found no evidence in Twain's papers or speeches that he ever said it about San Francisco. Wikiquote lists it as often attributed to Twain but of unknown origin. The joke itself is old, and it has been told about many places.
Where the joke came from
The earliest form Quote Investigator found is in a letter written by Horace Walpole in July 1789, which credits the actor James Quin: asked if he had ever seen so bad a winter, Quin replied, “Yes, just such an one last summer!”
Twain knew the joke. In a letter of 1880, viewable at the Mark Twain Project, he complained about the weather in Paris and retold it: “More than a hundred years ago somebody asked Quin, ‘Did you ever see such a winter in all your life before?’ ‘Yes,’ said he, ‘Last summer.’ I judge he spent his summer in Paris.”
How it reached San Francisco
The modern wording was in use by 1901, about Duluth, Minnesota: a weather-bureau man told a Kentucky paper that “the coldest winter he ever experienced was the summer he spent in Duluth.” Over the next century the joke moved to Milwaukee, Buffalo, Puget Sound and San Francisco, among others. Quote Investigator found Twain's name attached by 1928, when the city was still Duluth, and attached to San Francisco by 1963.