Joe Lhota seemed astonished when rival Bill de Blasio declared this week that Rudy Giuliani’s mayoralty “was not a good period in our history.” Lhota wasn’t alone.

But de Blasio’s remark highlighted the huge differences between the two mayoral candidates — and showed as starkly as ever how different the city might be, depending on who wins the election.

For de Blasio, the Giuliani years were nothing more than a time of racial division that “hurt this city and held it back.” (As if de Blasio’s two-cities trope fosters unity.)

De Blasio seems to think what makes a good mayor is a matter of personality. Despite the runaway crime, filthy streets and failing schools of the Dinkins years, he prefers the aloof Dinkins (for whom he worked) over the “divisive” Giuliani.

Yet even folks who thought Rudy too confrontational are generally willing to credit him with New York’s spectacular reversal, particularly on crime.

Maybe that’s what de Blasio resents; he views Giuliani’s crime crackdown itself as racially divisive. And never mind that minorities benefited from it most.

Lhota, on the other hand, recognizes that Giuliani “was the man who started the renaissance in this city, who started the programs to make all New Yorkers safe.”

It’s to his credit that he wants to emulate the job Giuliani did. “We are one mayor away from unsafe streets, unsafe schools and unsafe fiscal policies,” Lhota said.

Lhota is way behind in the polls, and his odds of becoming mayor are looking increasingly slim.

But even if he loses, Lhota will have done voters a huge favor — because his mere candidacy is making it clear for them in which directions he and his rival would likely take the city.