According to most contemporary scholarship, Ecclesiastes was written during the time when the Greeks ruled over Jerusalem and the Jews, around 250 B.C.E.
Israel and the Jews had had a glorious past, but now the days of the kings were only a memory. After the exile came Persian rule. Then in 332 B.C.E. the armies of Alexander the GreatMacedonian leader who conquered the Persian empire and began spreading Greek culture into the east. More moved into the East and the world became Greek overnight. Thus at the time of the writing of Ecclesiastes, the Jewish community was but a small island in the vast sea of the Greek empire.
The Jews in Jerusalem at this time had heard of the mighty acts of God in their past, but God did not seem to be doing anything mighty for them in their day. They had heard of the powerful words of God through the prophets, and they had preserved those words, but God did not seem to be saying anything in their day. They did not deny God’s existence in heaven, but they were on earth, and God seemed distant and unreachable. Even their best theologians and philosophers were baffled when it came to the question of what God was doing (8:17). Individuals sought in vain for meaning in their work, in intellectual pursuits or in sophisticated pleasures, but nothing ever seemed satisfying. All was “vanity,” about as substantial and permanent as a puff of smoke. A once-powerful nation that was now weak, without good political leadership; a religious community skeptical about God’s involvement in their lives; people desperately searching for meaning–such was the situation that the Teacher who produced this essay had to address.