The answer to that question depends on a few factors (e.g. prior education and work experience, or whether one is studying to be a diocesan priest or a religious priest). The standard path of formation for a diocesan priest is to complete a BA in philosophy (3 years), an MA in theology (4 years), and one year of internship in a parish for a total of eight years.
Academic study, however, is only one aspect of formation for the priesthood. The post-synodal apostolic exhortation Pastores Dabo Vobis by Pope St. John Paul II lays out four pillars of priestly formation: human, spiritual, intellectual and pastoral (see PV, 42). Preparing to be a priest isn't simply a matter of earning degrees in philosophy and theology. It is about being formed to be a shepherd like the Good Shepherd, Jesus Christ. Before a bishop ordains a man to the priesthood he must be confident that the candidate is sufficiently prepared in all four pillars of formation.
Here I will only give a brief overview of the four pillars of formation. I strongly recommend reading all of Pastores Dabo Vobis if you are considering the priesthood or if you simply want to know more about priestly formation.
Human formation is fundamental. As the medieval saying goes, "grace builds on nature." "The whole work of priestly formation would be deprived of its necessary foundation if it lacked a suitable human formation" (PV, 43). The Holy Father goes on to say, "The priest, who is called to be a "living image" of Jesus Christ, head and shepherd of the Church, should seek to reflect in himself, as far as possible, the human perfection which shines forth in the incarnate Son of God and which is reflected with particular liveliness in his attitudes toward others as we see narrated in the Gospels" (PV, 43). Obviously, each of us will always have some human weaknesses that hinder our ability to live out the Gospel. The Church doesn't expect her priests to be humanly perfect, but all major obstacles (e.g. addictions to drugs, alcohol, pornography, video games, etc., uncontrolled temper, licentious behavior, excessive laziness) should be overcome prior to ordination. The need to overcome these obstacles may require extra time being added to the formation program for some candidates. Prior to ordination the cardinal virtues (i.e., prudence, temperance, justice, and fortitude) should be well established and visible in the candidate's life, he should have a well-formed conscience, and he should be able to live out the freedom he has gained in Christ with maturity and responsibility.
Though human formation is foundational in preparing for the priesthood, spiritual formation is central. It is the heart that pumps life to the other pillars. The spiritual life - our relationship with God - is the end and the beginning that should be a candidate's motivation in preparing for the priesthood. Of course, all Christians are called to cultivate a deep relationship with the Lord; however, the priest, since he is to act in persona Christi capitis must live in such a way that he leads all of his people to closer union with God. He does this particularly through his devotion to the Divine Office, which is the universal prayer of the Church, through the Sacraments (especially the Eucharist and confession), Scripture, Our Blessed Mother and the saints. Seminarians are to be trained in various forms of prayer and integrate them into their life.
The third pillar is intellectual formation. The Pope says, "[intellectual formation] can be seen as a necessary expression of, both human and spiritual formation: It is a fundamental demand of the human intelligence by which one "participates in the light of God's mind" and seeks to acquire a wisdom which in turn opens to and is directed toward knowing and adhering to God" (PV. 51). God is Truth, and the role of the intellect is to grasp and adhere to truth. Through his study of philosophy the seminarian should, if he is in a good philosophy program, learn to love wisdom. God reveals Himself to us in many ways, and our intellect must be formed in such a way that we are more readily able to perceive Him in all areas of study. Of course, the culmination of intellectual formation is the study of Sacred Scripture. God has revealed Himself to us in the Divine Word, so priests must be educated in such a way that they are able to share the Word with their parishioners.
Finally, there is pastoral formation, which seeks to integrate the reality that God is love into the life of the seminarian. The relationship that the seminarian develops with God through his spiritual and intellectual formation is one that is diffusive - it must be shared. Pastoral formation is more than simply learning some techniques of parish ministry. Through an integral pastoral formation the seminarian becomes more like the Good Shepherd and is able to apply the truths of the faith with prudence, justice, temperance, fortitude and love in any situation.
The primary setting for these pillars of formation is a seminary. Like the apostles, who left the normal routines of life to follow Jesus as a group, seminarians enter a community that is dedicated to following Christ and teaching them to be true disciples. The faculty of the seminary are specially chosen to foster this goal.
Despite the brevity of this overview of priestly formation, it should be clear that there isn't really a simple answer to the question, "how long does it take to become a priest?" It takes as long as is necessary for an individual candidate to be prepared. There are certain benchmarks that must be met, but formation isn't simply a matter of "checking off boxes". The goal is to form candidates to be like Christ, the Good Shepherd, and with the help of God's grace that goal is possible for those who have been called.