Isaac Newton developed his theory of gravity around 1665-1666, but he published the comprehensive law of universal gravitation later on July 7, 1687, in his work Mathematical Principles of Natural Philosophy (also known as Principia).
The famous story of Newton discovering gravity by seeing a falling apple occurred around 1665 or 1666. However, it took him about two decades to formulate the full theory with mathematical proof. He demonstrated that the same force that causes objects to fall on Earth also extends to the Moon and governs planetary motions, naming it "universal gravitation".
So, while the inspiration and initial ideas date back to about 1665-1666, the formal discovery and publication of the law of gravity were in 1687.