NEW YORK — U.S. stocks on Friday climbed to their first back-to-back weekly gain in more than a month, on optimism for action by global central banks to stabilize markets if needed after Greek elections.

"It's startling to see it move higher on the amazing amount of uncertainty that surrounds this Greek election Sunday," said Randy Frederick, managing director of trading and derivatives with the Schwab Center for Financial Research.

"This market has held up remarkably well on the specter of more quantitative easing, whether it's an official QE3 type of announcement or an extension of Operation Twist" — the Federal Reserve's bond-buying program, he added.

Up 1.7 percent for the week, the Dow Jones industrial average rose 115.26 points, or 0.9 percent, to 12,767.17.

The S&P 500 index climbed 13.74 points, or 1 percent, to 1,342.84, up 1.3 percent from the week-ago close.

The Nasdaq composite added 36.47 points, or 1.3 percent, to 2,872.80.

Friday marked the first back-to-back weekly rises for the Dow and S&P since April, and for the Nasdaq since the end of March.

Crude for July delivery gained 12 cents to end at $84.03 a barrel.

U.S. data Friday illustrated slowing global growth, with the nation's industrial output weakening in May and with a gauge of manufacturing activity in the New York region slumping in June.

"The industrial production numbers weren't good at all; neither were New York manufacturing. Part of the problem is the dollar has risen against the euro, that hurts exports," Frederick said.

The University of Michigan-Thomson Reuters consumer-sentiment index fell to a preliminary June reading of 74.1 from 79.3 in May.

"Market volatility trumps lower gasoline prices is my take on that," Frederick said of the mood of the American consumer.

The dollar fell against other global currencies, including the euro, while the 10-year Treasury note yield used in determining mortgages and other consumer loans fell to 1.582 percent.