حَدَّثَنِي مُحَمَّدُ بْنُ بَشَّارٍ، حَدَّثَنَا مُحَمَّدُ بْنُ جَعْفَرٍ، حَدَّثَنَا شُعْبَةُ، عَنْ مُحَمَّدِ بْنِ زِيَادٍ، عَنْ أَبِي هُرَيْرَةَ، عَنِ النَّبِيِّ صلى الله عليه وسلم ‏"‏ إِنَّ عِفْرِيتًا مِنَ الْجِنِّ تَفَلَّتَ الْبَارِحَةَ لِيَقْطَعَ عَلَىَّ صَلاَتِي، فَأَمْكَنَنِي اللَّهُ مِنْهُ، فَأَخَذْتُهُ، فَأَرَدْتُ أَنْ أَرْبُطَهُ عَلَى سَارِيَةٍ مِنْ سَوَارِي الْمَسْجِدِ حَتَّى تَنْظُرُوا إِلَيْهِ كُلُّكُمْ فَذَكَرْتُ دَعْوَةَ أَخِي سُلَيْمَانَ رَبِّ هَبْ لِي مُلْكًا لاَ يَنْبَغِي لأَحَدٍ مِنْ بَعْدِي‏.‏ فَرَدَدْتُهُ خَاسِئًا ‏"‏‏.‏ عِفْرِيتٌ مُتَمَرِّدٌ مِنْ إِنْسٍ أَوْ جَانٍّ، مِثْلُ زِبْنِيَةٍ جَمَاعَتُهَا الزَّبَانِيَةُ‏.‏
Translation
Narrated Abu Dhaar

I said, "O Allah's Messenger (ﷺ)! Which mosque was built first?" He replied, "Al-Masjid-ul-Haram." I asked, "Which (was built) next?" He replied, "Al-Masjid-ul-Aqs-a (i.e. Jerusalem)." I asked, "What was the period in between them?" He replied, "Forty (years)." He then added, "Wherever the time for the prayer comes upon you, perform the prayer, for all the earth is a place of worshipping for you."