Results 1 to 6 of 6

Thread: Daily iFrame: How to show day based on one timezone?

  1. #1
    Join Date
    Apr 2012
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Daily iFrame: How to show day based on one timezone?

    1) Script Title: Daily iframe content

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici.../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!

    Code:
    <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
    daycontent[3]="wednesday.htm"
    daycontent[4]="thursday.htm"
    daycontent[5]="friday.htm"
    daycontent[6]="saturday.htm"
    daycontent[0]="sunday.htm"
    
    //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
    iframeobj.src=daycontent[mytoday]
    }
    }
    
    window.onload=dayofweek_iframe
    
    </script>
    Last edited by Dobbs_82; 04-01-2012 at 06:44 AM.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Replace:

    Code:
    var mydate=new Date()
    var mytoday=mydate.getDay()
    with:

    Code:
    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    Dobbs_82 (04-01-2012)

  4. #3
    Join Date
    Apr 2012
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Will

    Code:
    mydate.setHours(mydate.getHours()+mydate.getTimezoneOffset()/60-4)
    work also?

  5. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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:

    http://www.worldtimeserver.com/curre..._in_CA-NF.aspx

    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. The Following User Says Thank You to jscheuer1 For This Useful Post:

    Dobbs_82 (04-02-2012)

  7. #5
    Join Date
    Apr 2012
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Ok thank you very much, I will use the minutes code instead.

  8. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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)
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •