It completely depends on your objective.
If all you want is to learn basic things e.g. how to order a beer in a bar or how to count until 10, a 30-minute one-off class should be enough. Another example: Specific Course: Spanish to Stay Afloat is a programme designed to be covered in around 15 hours of classes.
However, if your goal is to achieve an upper-intermediate level of Spanish, i.e. to get to at least B2 level, you will have to dedicate quite some time. The estimated number of hours of classes you need to cover the material from A1 level is 60h, A2- 120h, B1- 180h and B2- 180h. This way, if your objective is to get to B2 level, you will need around 540h of classes. As a reference, if you want to have 2 hours of classes per week with no breaks for holidays, in order to meet this target you will need around 5 years.
Of course it also depends on other factors, e.g. your mother tongue, your knowledge of other foreign languages, if you already live in Spain, if you do homework regularly, if you practice Spanish outside the classroom, etc.