Results 1 to 10 of 10

Thread: Help with Live Date Script

  1. #1
    Join Date
    Jun 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with Live Date Script

    Script: Live Date Script
    http://www.dynamicdrive.com/dynamicindex6/clock3.htm

    Can someone please help me how to make it so that I can change the timezone of the date and time?

  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

    This assumes daylight savings time or summertime (whichever is used in the time zone you configure the script for) starts on the first Sunday of April and ends on the last Sunday in October. Configure the three red variables and you are set (this one's set for the Pacific Time Zone of the USA):

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    </head>
    <body onLoad="goforit()">
    <script>
    
    /*
    Live Date Script- 
     Dynamic Drive (www.dynamicdrive.com)
    For full source code, installation instructions, 100's more DHTML scripts, and Terms Of Use,
    visit http://www.dynamicdrive.com
    */
    
    var timeZone=-8  //set to time zone's offset from Universal Time
    var timeZoneString='PST' //set to time zone's label
    var daylight='PDT'  //set to time zone's daylight or summertime label
    
    var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
    var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
    
    function isDST2(year){
    var t1,t2;
    for (var i_tem = 1; i_tem < 8; i_tem++){
    t1=new Date(year, 3, i_tem)
    if (t1.getDay()==0)
    break;
    }
    for (var i_tem = 31; i_tem > 24; i_tem--){
    t2=new Date(year, 9, i_tem)
    if (t2.getDay()==0)
    break
    }
    return [t1.getDate(), t2.getDate()]
    }
    
    function isDST(){
    /*DST on (+1 hour): first Sunday of April, 02:00 local time.
    DST off: last Sunday of October, 02:00 local time.*/
      var TimezoneOffset = timeZone  // adjust for time zone
      var localTime = new Date()
      var ms = localTime.getTime() 
                 + (localTime.getTimezoneOffset() * 60000)
                 + TimezoneOffset * 3600000
      var time =  new Date(ms) 
    
      if(time.getMonth()<3||time.getMonth()>9)
    return 0
      else if(time.getMonth()>3&&time.getMonth()<9)
    return 1
      else if (time.getMonth()==3&&time.getDate()>7)
    return 1
      else if (time.getMonth()==3){
    if(time.getDate()>isDST2(time.getFullYear())[0])
    return 1
    if(time.getDate()==isDST2(time.getFullYear())[0]&&(time.getHours()>1||(time.getHours()==1&&time.getMinutes()>58)))
    return 1
    return 0
      }
    if(time.getDate()<isDST2(time.getFullYear())[1])
    return 1
    if(time.getDate()==isDST2(time.getFullYear())[1]&&(time.getHours()<1||(time.getHours()==1&&time.getMinutes()<59)))
    return 1
    return 0
    }
    
    function getthedate(){
      var TimezoneOffset = timeZone + isDST() // adjust for time zone
      var localTime = new Date()
      var ms = localTime.getTime() 
                 + (localTime.getTimezoneOffset() * 60000)
                 + TimezoneOffset * 3600000
     
    var mydate=new Date(ms)
    var year=mydate.getYear()
    if (year < 1000)
    year+=1900
    var day=mydate.getDay()
    var month=mydate.getMonth()
    var daym=mydate.getDate()
    if (daym<10)
    daym="0"+daym
    var hours=mydate.getHours()
    var minutes=mydate.getMinutes()
    var seconds=mydate.getSeconds()
    var dn="AM"
    var z=isDST()==1? daylight : timeZoneString;
    if (hours>=12)
    dn="PM"
    if (hours>12){
    hours=hours-12
    }
    if (hours==0)
    hours=12
    if (minutes<=9)
    minutes="0"+minutes
    if (seconds<=9)
    seconds="0"+seconds
    //change font size here
    var cdate="<small><font color='000000' face='Arial'><b>"+dayarray[day]+", "+montharray[month]+" "+daym+", "+year+" "+hours+":"+minutes+":"+seconds+" "+dn
    +" "+z+"</b></font></small>"
    if (document.all)
    document.all.clock.innerHTML=cdate
    else if (document.getElementById)
    document.getElementById("clock").innerHTML=cdate
    else
    document.write(cdate)
    }
    if (!document.all&&!document.getElementById)
    getthedate()
    function goforit(){
    if (document.all||document.getElementById)
    setInterval("getthedate()",1000)
    }
    
    </script>
    <span id="clock"></span>
    </body>
    </html>
    - John
    ________________________

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

  3. #3
    Join Date
    Jun 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you!

  4. #4
    Join Date
    Nov 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Im also having trouble with the dynamic time script.

    I want to run it using asp.

    The problem im getting is that it is running the correct time but exactly 3 days late.

    here is the entire page so far. Im new to web building and learning as i go, so go easy on me ok. Ive tried to follow your instructions on your web site and something is wrong.

    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">

    <link rel="stylesheet" type="text/css" href="_themes/deepblue/deep1011.css"><!--mstheme--><link rel="stylesheet" type="text/css" href="_themes/deepblue/deep1011.css"><meta name="Microsoft Theme" content="deepblue 1011">

    <head>
    <script type="text/javascript">

    /***********************************************
    * Local Time script- &#169; Dynamic Drive (http://www.dynamicdrive.com)
    * This notice MUST stay intact for legal use
    * Visit http://www.dynamicdrive.com/ for this script and 100s more.
    ***********************************************/

    var weekdaystxt=["Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat"]

    function showLocalTime(container, servermode, offsetMinutes, displayversion){
    if (!document.getElementById || !document.getElementById(container)) return
    this.container=document.getElementById(container)
    this.displayversion=displayversion
    var servertimestring=(servermode=="server-php")? '<? print date("F d, Y H:i:s", time())?>' : (servermode=="server-ssi")? '<!--#config timefmt="%B %d, %Y %H:%M:%S"--><!--#echo var="DATE_LOCAL" -->' : '<%= Now() %>'
    this.localtime=this.serverdate=new Date(servertimestring)
    this.localtime.setTime(this.serverdate.getTime()+offsetMinutes*60*1000) //add user offset to server time
    this.updateTime()
    this.updateContainer()
    }

    showLocalTime.prototype.updateTime=function(){
    var thisobj=this
    this.localtime.setSeconds(this.localtime.getSeconds()+1)
    setTimeout(function(){thisobj.updateTime()}, 1000) //update time every second
    }

    showLocalTime.prototype.updateContainer=function(){
    var thisobj=this
    if (this.displayversion=="long")
    this.container.innerHTML=this.localtime.toLocaleString()
    else{
    var hour=this.localtime.getHours()
    var minutes=this.localtime.getMinutes()
    var seconds=this.localtime.getSeconds()
    var ampm=(hour>=12)? "PM" : "AM"
    var dayofweek=weekdaystxt[this.localtime.getDay()]
    this.container.innerHTML=formatField(hour, 1)+":"+formatField(minutes)+":"+formatField(seconds)+" "+ampm+" ("+dayofweek+")"
    }
    setTimeout(function(){thisobj.updateContainer()}, 1000) //update container every second
    }

    function formatField(num, isHour){
    if (typeof isHour!="undefined"){ //if this is the hour field
    var hour=(num>12)? num-12 : num
    return (hour==0)? 12 : hour
    }
    return (num<=9)? "0"+num : num//if this is minute or sec field
    }

    </script>

    </head>

    <body>

    Current Server Time:<span id="timecontainer"></span><br />
    Current LA Time:<span id="timecontainer2"></span><br />
    Current New York Time:<span id="timecontainer3"></span><br />
    Current Chicago Time:<span id="timecontainer4"></span><br />
    Current Sydney:<span id="timecontainer5"></span><br />
    Current Perth:<span id="timecontainer6"></span><br />
    Current Berlin:<span id="timecontainer7"></span><br />
    Current London:<span id="timecontainer8"></span><br />


    <script type="text/javascript">
    new showLocalTime("timecontainer", "server-asp", 0, "short")
    new showLocalTime("timecontainer2", "server-asp", 0, "short")
    new showLocalTime("timecontainer3", "server-asp", -180, "short")
    new showLocalTime("timecontainer4", "server-asp", -120, "short")
    new showLocalTime("timecontainer5", "server-asp", -1140, "short")
    new showLocalTime("timecontainer6", "server-asp", -960, "short")
    new showLocalTime("timecontainer7", "server-asp", -540, "short")
    new showLocalTime("timecontainer8", "server-asp", -480, "short")

    </script>



    </body>

    </html>

  5. #5
    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

    First off, there are many time and date scripts in the DD library, this is a different one than the one that this thread was started with. Because of that, you should probably have started a new thread - usually a good idea even if you have a similar question about the same script.

    Be that as it may, this line:

    Code:
    new showLocalTime("timecontainer", "server-asp", 0, "short")
    should be showing the server time/date in this:

    HTML Code:
    Current Server Time:<span id="timecontainer"></span><br />
    container. If that is off, then the date on the server and/or on the local computer is most likely off.
    - John
    ________________________

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

  6. #6
    Join Date
    Nov 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    Thanks john for replying to my question.

    Ill now go and try and implement it.

    again thankyou

  7. #7
    Join Date
    Mar 2010
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi everyone,
    I'm having trouble with the Live Date script.
    I have loaded into a table at www.flockofpigs.co.uk/dpc.co.uk

    It should appear in the top right-hand corner but isn't showing... anyone got any ideas?

    Thanks
    Phil

  8. #8
    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

    Quote Originally Posted by Flock001 View Post
    Hi everyone,
    I'm having trouble with the Live Date script.
    I have loaded into a table at www.flockofpigs.co.uk/dpc.co.uk

    It should appear in the top right-hand corner but isn't showing... anyone got any ideas?

    Thanks
    Phil
    You have an onload conflict. Get rid of this highlighted bit from your body tag:

    Code:
    <body onLoad="goforit()">
    Add this highlighted bit to the end of the Live Date script:

    Code:
     . . . ument.all&&!document.getElementById)
    getthedate()
    function goforit(){
    if (document.all||document.getElementById)
    setInterval("getthedate()",1000)
    }
    
    if (window.addEventListener){
    	window.addEventListener('load', goforit, false);
    }
    else if (window.attachEvent){
    	window.attachEvent('onload', goforit);
    }
    - John
    ________________________

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

  9. #9
    Join Date
    Mar 2010
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks John,

    However... it hasn't solved the issue.
    Got any other ideas?

    Thanks
    Phil

  10. #10
    Join Date
    Mar 2010
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Scratch that last message, it's appeared now.
    You're a gem!

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
  •