Well, define gun. Metal, something like we know it today? @PandoraBoxx is right. But if you mean gunpowder-based weaponry, such as a bamboo tube packed with the stuff, used to shoot spearlike projectiles, it’s a little earlier. Some say mid-10th century, or even late 9th century China. Gunpowder came about in the 800s.
An interesting aside here is that people who wish to ban all use of guns would have to reduce us all back to 8th century technology. ;)