Answer: Before George Washington took office as our first President under the Constitution.
Keep in mind that prior to July 4, 1776, any attack against an “American” ship would have been considered an attack against Great Britain, which had a formidable navy.
And during the American Revolution, we had the support of the French navy.
But once the war was over, we were on our own, and did not have a navy. Muslim terrorists recognized this, and attacked U.S. ships.
In 1784, Congress authorized American diplomats John Adams, Benjamin Franklin, and Thomas Jefferson to negotiate with the Muslim terrorists.  Negotiations proceeded, and in 1786, John Adams and Thomas Jefferson candidly asked the Ambassador from Tripoli the motivation behind their unprovoked attacks against Americans. What was the response?
The Ambassador answered us that it was founded on the laws of their Prophet [Mohammed] – that it was written in their Koran that all nations who should not have acknowledged their authority were sinners; that is was their right and duty to make war upon them wherever they could be found and to make slaves of all they could take as prisoners; and that every Musselman [Muslim] who should be slain in battle was sure to go to Paradise. 
- George Washington, Writings, Vol. 28, p. 521, to Marquis de Lafayette, August 15, 1786.