Quote:
Originally Posted by davidwhite
Let's just keep it simple and assume it changes 8.00am UTC for everyone, no matter what their local time is.
|
It would seem to be better to change at 0800 local time for everyone, but if for some reason every user must see the same image (why?) then why change at 0800 rather than midnight UTC?
<img id = "myimage" src = "">
<script type = "text/javascript">
// change image at 0800 UTC daily
var pics = [];
pics[0] = "Sunday.jpg";
pics[1] = "Monday.jpg";
pics[2] = "Tuesday.jpg";
pics[3] = "Wednesday.jpg";
pics[4] = "Thursday.jpg";
pics[5] = "Friday.jpg";
pics[6] = "Saturday.jpg"
var d = new Date(); // today
var hr = 8; // hours to subtract (or add)
var off = d.getTimezoneOffset(); // offset in minutes
off = off *60*1000; // offset in milliseconds
d = d.getTime() - (3600000*hr) - off; // subtract hr hours and timezone offset
var nd = new Date(d);
var dy = nd.getDay();
document.getElementById("myimage").src = pics[dy];
</script>
Note that Javascript relies on the accuracy of the user's computer clock. If it is important that all users always see the same image then you need server-side scripting.