View Full Version : Daily iFrame: How to show day based on one timezone?

04-01-2012, 06:37 AM
1) Script Title: Daily iframe content

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/dowiframe.htm

3) Describe problem: This is a wonderful script but I have ran into an issue. How do I force the day of the week to change on an Eastern timezone only (GMT -4)? I need everyone to be on the same day, regardless of when their computer hit midnight. Any help would be greatly appreciated! Thanks!

<script language="JavaScript1.2">

//Daily iframe content- Dynamic Drive (www.dynamicdrive.com)
//For full source code, and Terms Of use, visit http://dynamicdrive.com
//This credit MUST stay intact for use

var ie=document.all&&navigator.userAgent.indexOf("Opera")==-1
var dom=document.getElementById&&navigator.userAgent.indexOf("Opera")==-1

//Specify IFRAME display attributes
var iframeprops='width=150 height=150 marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="1" scrolling="no"'

//Specify 7 URLs to display inside iframe, one for each day of week
var daycontent=new Array()
daycontent[1]="monday.htm" //Monday content
daycontent[2]="tuesday.htm" //Tuesday content

//No need to edit after here
if (ie||dom)
document.write('<iframe id="dynstuff" src="" '+iframeprops+'></iframe>')

var mydate=new Date()
var mytoday=mydate.getDay()

function dayofweek_iframe(){
if (ie||dom){
var iframeobj=document.getElementById? document.getElementById("dynstuff") : document.all.dynstuff



04-01-2012, 11:16 AM

var mydate=new Date()
var mytoday=mydate.getDay()


var mydate=new Date()
mydate.setMinutes(mydate.getMinutes() + mydate.getTimezoneOffset() - 4 * 60);
var mytoday=mydate.getDay()

By adding the time zone offset, the date is converted to GMT. Then by subtracting 4 times 60 minutes, EDT is calculated.

04-01-2012, 04:52 PM


work also?

04-01-2012, 07:11 PM
No, because the timezone offset can be a value that represents fractions of an hour. Most timezones around the world are incremented/decremented by whole hours, but a few, at least one, at least last I looked, are not.

Just checked again:


Newfoundland at least is a half hour different from others in its longitudinal zone.

Another thing to consider is that during daylight savings time, 4hrs is correct, but the rest of the time it's 5 hrs. You can either change that manually as the clocks change or work out a function for it. But, as you're looking for whole days, one hour off in winter isn't going to be that big of a deal.

04-02-2012, 12:58 AM
Ok thank you very much, I will use the minutes code instead.

04-02-2012, 01:26 AM
If you're interested, I think I have a fairly good function worked out to detect EDT. It assumes, as is currently the standard, that EDT starts on the 2nd Sunday in March and ends on the first Sunday in November at 7hrs UTC time for each.

Speaking of time, why do mathematicians confuse Halloween and Christmas?

Because Oct 31 = Dec 25. (octal - base 8 - 31 equals decimal - base 10 - 25)