(Reuters) - U.S. military officials would have preferred the United States not announce a date for ending its troop presence in Afghanistan, as the White House did in May, the outgoing commander of U.S. forces there said on Thursday.

General Joe Dunford, commander of U.S. and NATO troops in Afghanistan, was asked at a Senate committee hearing whether President Barack Obama's announcement that almost all U.S. troops would be gone by 2017 had damaged morale among Afghan soldiers.

"I think all of us in uniform, to include the Afghans, would have preferred that that be a bit more ambiguous," Dunford said.

He was responding to a question by Republican Senator John McCain Of Arizona, a persistent critic of Obama's Afghanistan policy, during a hearing on Dunford's nomination to become the next head of the U.S. Marine Corps.

The White House announced in May that if a bilateral troop deal is signed in time, it plans to keep a residual force of 9,800 soldiers in Afghanistan after the current international military mission ends in December.

That force would gradually be reduced and by the end of 2016 there would be only a small number of soldiers left at the U.S. embassy under the authority of the U.S. ambassador, as the United States had in Baghdad after its 2011 withdrawal from Iraq.

McCain asked whether any senior military leaders had recommended setting a fixed date for a full pullout of the U.S. military force, and whether Dunford would have preferred that future troops levels be based on evolving security conditions.

"None that I know of, senator. And - and I think we still plan to have, as you know, some presence after 2017. But no one recommended zero," he said.

"Every military leader would want to have the conditions on the ground and the assumptions be revalidated as a transition takes place," he said.

As foreign troops leave, Afghanistan's military is taking charge of the fight against Taliban and other militants, even as the country grapples with uncertainty resulting from a disputed second round of presidential voting last month.

Dunford said Afghan security forces, while greatly improved, may be unable to conduct effective operations against militants when the United States departs.

"There's no doubt that the Afghan forces today would not be capable of conducting the kind of operations we're conducting to pressure on the network" of militants in Afghanistan, Dunford said. He said he expected that Afghan forces would not have that capability by 2017 if the current militant threat persisted.