"I was not born in the castle. I come from a distant land. A traveler gave me to Hagrid when I was an egg. Hagrid was only a boy, but he cared for me, hidden in a cupboard in the castle, feeding me on scraps from the table."
Hagrid obtains the egg while a student at Hogwarts, and has to keep Aragog a secret (CS15).
This happened somewhere between Hagrid starting at Hogwarts in the fall of 1940, and his expulsion in the spring of 1943 (CS).
There is a parallel between 1) Harry living in a spider-infested cupboard, hidden and kept secret by the abusive people who are the closest thing he has to parents, before learning that he gets to go to Hogwarts and having his axistence acknowledged and 2) Aragog being hidden in a cupboard and raised and cared for there by Hagrid, who was very much on his own, until Aragog's discovery causes Hagrid to be expelled from Hogwarts. -BB