CINXE.COM

<!DOCTYPE html> <html> <head> <script> ///////////////////////////////////////////////////// // Random APOD Date Generator // // by Geckzilla aka Judy Schmidt www.geckzilla.com // // Copy it, share it, modify it--I don't mind. // ///////////////////////////////////////////////////// var now = new Date(); //right now var min = new Date(1995, 5, 16).getTime(); // 1995 June 16 00:00:00, the first APOD var max = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), 18, 59, 59, 999).getTime(); // now converted UTC time at 03:59:59.999 //taking off 6 hours because APOD goes by east coast USA time. //should be enough to keep anyone from landing on future APODs which won't be published yet in their timezone //unless their computer clock is set way off, then they'll get 404's all the time probably max = max-(5*60*60*1000); var random_date = Math.round(min+(Math.random()*(max-min))); //ahh, a random APOD date! //but wait... //there's one section of missing APODs in the history of APODs //that's the first three days after the very first APOD was posted //June 17th, 18th, & 19th, 1995 var missing_min = new Date(1995, 5, 17).getTime(); //1995 June 17 00:00:00 var missing_max = new Date(1995, 5, 19, 23, 59, 59, 999).getTime(); //1995 June 19 23:59:59.999 //if our random date falls in this range, remake it. while(random_date >= missing_min && random_date <= missing_max) { random_date = Math.round(min+(Math.random()*(max-min))); } //convert the timestamp back into a date object random_date = new Date(random_date); random_year = random_date.getFullYear().toString().slice(-2); //in the year 2095 we're gonna have problems random_month = (0+(random_date.getMonth()+1).toString()).slice(-2); //zero pad the month random_day = (0+(random_date.getDate().toString())).slice(-2); //zero pad the day var final_html = '<iframe src="https://apod.nasa.gov/apod/ap'+random_year+random_month+random_day+'.html" id="apod"></iframe>'; </script> <meta charset="UTF-8"> <style> body, html { margin: 0; padding: 0; } #apod { position: absolute; top: 5%; width: 100%; height: 95%; border: 0; } #rand { position: absolute; width: 100%; height: 5%; box-shadow: 0 -2px 10px black inset; background: #4d4d72; } #rand a { text-decoration: none; font-family: Verdana, sans-serif; color: #d1d1ff; font-size: 16px; display: block; width: 100%; top: 25%; text-align: center; position: absolute; } </style> </head> <body> <script>document.write(final_html)</script> <div id="rand"><a href="random_apod.html">Click here for another random APOD.</a></div> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10