If there was ever a real-life situation where one side had spearmen to fight against a modern tank, this is what would happen:
1. Spearmen have a chance winning against a tank if they were spread apart enough. Travelling in groups is stupid and makes it easier to take them out with the tank's cannon (which is really powerful).
2. However, if the tank was also equipped with a machine gun turret, this enables the soldiers to take out spearmen that the cannon doesn't. If the spearmen are very skilled at throwing, they can probably kill the person wielding the turret. But before they even do that, the turret would have already killed dozens of troops before they get him. If the machine gun was remote-controlled from the inside, you are screwed.
3. Soldiers in the tank are usually equipped with firearms. Sometimes they carry pistols, sometimes assault rifles. The fate of the spearmen also depends on whether their armor will also be able to withstand and maybe deflect bullets, and also how good they are at dodging bullets (which is highly unlikely they will, as armor from previous eras seem to weight a lot more).
4. If you had an army of spearmen, you would have a much better chance of winning against a single tank since you're trying to overwhelm it, but multiple tanks would be almost impossible and I really doubt a civilization would sacrifice so many soldiers in what is inevitable.
5. Spears do not even dent the armor of tanks. Spears are made of iron or copper. The armor of tanks are made of very strong heat-treated steel alloys. Other metals used are aluminum, magnesium, and titanium. The armor of tanks used in World War II were around 2 to 6 inches thick.
6. Tanks can be disabled by overturning it. If spearmen took all their crap off and just ran, they would have a chance of making it to the tank, under the range of the cannon and machine gun turret. Just let it be known that modern tanks weigh about 60 tons so good luck getting that many people to make it, more or less getting to lift over 60 tons. Also, tanks can move at around 40 miles per hour on good terrain also so overturning it is impossible if it is properly controlled by an engineer. If it was stuck in mud or some really bad position, then spearmen would have more of a chance.
7. Spearmen should not fight at night because they are giving themselves a disadvantage. They won't see as well, but modern tanks are equipped with night-vision technology and even lock-on features, and therefore can own any spearmen at any time of the day.
8. A cannon has the range of over 1,000 meters. The world record (maybe outdated?) for throwing a frisbee is only 406 meters of 1,333 feet. The number is much lower for javelins, so think of those numbers when you're going against a tank with a spear.
In conclusion, in a real-life situation where if spearmen fought a tank, a tank would absolutely obliterate spearmen practically 99% of the time.