All perfect praise be to Allah, The Lord of the worlds. I testify that there is none worthy of worship except Allah and that Muhammad is His slave and Messenger.
There is no doubt that the Prophet did not know when the Hour (Doomsday) will take place; it is only Allah Who knows best about it.
Allah says (what means): {They ask you [O Muhammad] about the Hour: when is its arrival? Say, "Its knowledge is only with my Lord. None will reveal its time except Him. It lays heavily upon the heavens and the earth. It will not come upon you except unexpectedly." They ask you as if you are familiar with it. Say, "Its knowledge is only with Allah, but most of the people do not know."} [Quran 7:187]
The approach of the Day of Judgment was mentioned by revelation from Allah in the Quran and in the Sunnah.
Allah says (what means): {[The time of] their account has approached for the people, while they are in heedlessness turning away.} [Quran 21:1]
Allah also says (what means): {The Hour has come near, and the moon has split [in two]} [Quran 54:1]
As regards the hadeeth, Anas narrated that the Prophet said, “When I was sent, I and the Hour were like these two - holding his index and middle fingers together.” [Al-Bukhari and Muslim]
The Prophet is truthful in what he conveys about Allah as he speaks by what was revealed to him by Allah. Allah says (what means): {Nor does he speak from [his own] inclination. It is not but a revelation revealed.} [Quran 53:3-4]
Allah knows best.