SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot virginiamonkeys's Avatar
    Join Date
    Jun 2003
    Location
    Stafford, Virginia, USA
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need help to get this to count from the start of the year

    I have this script below that I want to count from the beginning of the year, January 1st.

    It's counting from the time the page loads right now.

    How do I modify it? Thanks.

    HTML Code:
    <script>
    // CREDITS:
    // Realtime Death Counter 2.01
    // By Peter Gehrig
    // Copyright (c) 2003 Peter Gehrig. All rights reserved.
    // Permission given to use the script provided that this notice remains as is.
    // Additional scripts can be found at http://www.24fun.com
    // info@24fun.com
    // 10/6/2003
    // The script is based on statistics by World Health Organisation
    
    // IMPORTANT:
    // If you add this script to a script-library or script-archive
    // you have to add a highly visible link to
    // http://www.24fun.com on the webpage
    // where this script will be featured
    
    var cause=new Array()
    
    // delete or add new crimes like this: 
    // cause[x]="crime|number of incidents per year"
    cause[0]="<strong>All Criminal Offenses in USA</strong>|11877218"
    cause[1]="<strong>Violent Crime</strong>|1426325"
    cause[2]="Murder and Nonnegligent Manslaughter|16204"
    cause[3]="Forcible Rape|95136"
    cause[4]="Robbery|420637"
    cause[5]="Aggravated Assault|894348"
    cause[6]="<strong>Property Crime Total</strong>|10450893"
    cause[7]="Burglary|2151875"
    cause[8]="Larceny-Theft|7052922"
    cause[9]="Motor Vehicle Theft|1246096"
    cause[10]="<strong>All Criminal Offenses in Virginia</strong>|229039"
    cause[11]="<strong>Violent Crime</strong>|21256"
    cause[12]="Murder and Nonnegligent Manslaughter|388"
    cause[13]="Forcible Rape|1839"
    cause[14]="Robbery|6961"
    cause[15]="Aggravated Assault|12068"
    cause[16]="<strong>Property Crime Total</strong>|207783"
    cause[17]="Burglary|31757"
    cause[18]="Larceny-Theft|157548"
    cause[19]="Motor Vehicle Theft|18478"
    
    
    
    // font
    var thisfont="Arial"
    
    // font-size
    var thissize=9
    
    // font-color
    var thiscolor="4c004b"
    
    
    // font of title
    var titlefont="Arial"
    
    // font-size of title
    var titlesize=9
    
    // font-color
    var titlecolor="#ffffff"
    
    
    // backgroundcolor title
    var titlebg="#4c004b"
    
    // backgroundcolor crime counter
    var bg="#e0c8e0"
    
    
    // do not edit below this line
    var t = 0
    var enterTime = new Date()
    var enterTime = Math.floor(enterTime.getTime()/1000)
    var secyear=31536000
    var rowflag=false
    var i_causes=0
    
    if (document.getElementById) {
    	initdisplay()
    }
    
    function initdisplay() {
    	document.write('<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 bgcolor="'+bg+'">')
    	document.write('<tr valign=top>')
    	document.write('<td colspan=4 style="font-family:'+titlefont+';font-size:'+titlesize+'pt;color:'+titlecolor+';background-color:'+titlebg+'" 
    
    id="titlecell" align=center>')
    	document.write('&nbsp;&nbsp;Realtime Crime Counter:<BR>Crimes committed within the last 0 seconds')
    	document.write('</td></tr>')
    
    	document.write('<tr valign=top>')
    	document.write('<td colspan=2>')
    	document.write('&nbsp;')
    	document.write('</td></tr>')
    	document.write('<tr valign=top>')
    	document.write('<td><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0>')
    	for (i=0; i<=cause.length-1; i++) {
    		var content=cause[i].split("|")
    		document.write('<tr valign=top>')
    		document.write('<td align=right id="cell'+i+'" style="font-family:'+thisfont+';font-size:'+thissize+'pt;color:'+thiscolor+'">')
    		document.write('empty')
    		document.write('</td>')
    		document.write('<td>')
    		document.write('&nbsp;&nbsp;')
    		document.write('</td>')
    		document.write('<td align=left style="font-family:'+thisfont+';font-size:'+thissize+'pt;color:'+thiscolor+'">')
    		document.write(content[0]+" ")
    		document.write('</td>')
    		document.write('</tr>')
    		i_causes++
    	}
    	document.write('</TABLE></td>')
    	document.write('<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>')
    }
    
    
    function docounter() {
    	var now = new Date()
    	var now=Math.floor((now.getTime()/1000))
    	var hereSince = now - enterTime
    	for (i=0; i<=cause.length-1; i++) {
    		var content=cause[i].split("|")
    		content[1]=Math.floor(content[1]/secyear*hereSince)
        	document.getElementById('cell'+i).innerHTML=content[1]
        	document.getElementById('titlecell').innerHTML="&nbsp;&nbsp;Realtime Crime Counter:<BR>Crimes committed within the last "+hereSince+" seconds"
    	}	
    	var setT = setTimeout("docounter()",1000)		
    }
    
    
    function showNr(zahlProSec,hereSi,gifNa) {
    
    	var zahlSince = ""+Math.floor(hereSi*zahlProSec) 
    	var rechtsPos = 9 -	zahlSince.length-1
    
    	for (i=0; i<= zahlSince.length-1; i++) {
    		document.images[gifNa+(i+rechtsPos)].src = "z"+zahlSince.charAt(i)+".gif"
    	}
    }
    
    if (document.getElementById) {
    	window.onload=docounter
    }
    </script>

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Portsmouth UK
    Posts
    1,499
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    new Date(2005)

  3. #3
    SitePoint Zealot virginiamonkeys's Avatar
    Join Date
    Jun 2003
    Location
    Stafford, Virginia, USA
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, that's close, but the script is counting at 1104520681 seconds, which is about 35.02 times longer than the date is supposed to be. Each year according to the script has 31536000 seconds in it.

    I changed the
    var enterTime = new Date()
    to read
    var enterTime = new Date(2005)

  4. #4
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Portsmouth UK
    Posts
    1,499
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I ment somthing like

    var StartTime = new Date(2005)

    var enterTime = new Date()

    YearTime=enterTime-StartTime;


    but got called away

    PHP Code:

    // do not edit below this line
    var 0
    var enterTime = new Date(2005,0,1);
    var 
    enterTime Math.floor(enterTime.getTime()/1000)
    var 
    secyear=31536000
    var rowflag=false
    var i_causes=
    Last edited by vwphillips; Jan 1, 2005 at 03:19.


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
  •