Oil shares were helped by rising crude prices, and confidence was boosted by news of a deal over financial assistance for Greece.
The Dow Jones Industrial Average rose 145.46 points to 17851.51.
The wider S&P 500 index rose 14.48 points to 2090.54, while the Nasdaq index gained 33.84 to 4894.89
"The market is embracing the idea that if the Fed moves in June or July, the bull market can continue, so we have an economy that is growing at a modest pace," said Alan Skrainka, chief investment officer at Cornerstone Wealth Management.
Chevron shares rose 1.6% and Exxon Mobile was up 0.7%, as the price of US crude climbed 2.2% to $49.68 a barrel.
Shares in Computer Sciences jumped by 42% after Hewlett Packard Enterprise announced it would merge its IT services business with the company.
Hewlett Packard Enterprise shares climbed 6.8% to $17.35.
E-commerce giant Alibaba saw its share price fall 6.8% after it revealed its accounting practices were under investigation by US regulators.
(Closed): US stocks rose for a second day as investors began to take a more positive attitude to a potential rise in US interest rates in June.