njaohnt Posted September 19, 2011 Author Posted September 19, 2011 I don't see why that would help. The purpose of the page is so that users can see the difference between their time and the heliohost server. ... Any way http://jz.jzdb.heliohost.org/servertime.php Byron, it is not that problem. Quote
Guest xaav Posted September 19, 2011 Posted September 19, 2011 So, the beatified code: <html> <head> <title>Time</title> <script type="text/javascript"> function d() { var j = [18, 14, 37]; var t = new Date(); var c = [t.getHours, t.getMinutes, t.getSeconds]; var a = [c[0] - j[0], c[1] - j[1], c[2] - j[2]]; var b = "After Jz's"; if (a[0] < 0) { a[0] = j[0] - c[0]; b = "Before Jz's"; } if (a[1] < 0) a[1] = j[1] - c[1]; if (a[2] < 0) a[2] = j[2] - c[2]; for (i = 0; i < 3; i++) document.getElementById("r" + i).innerHTML = a[0]; document.getElementById("r").innerHTML = b; document.getElementById("t").innerHTML = "Your computer's date and time:" + Date() + "<br>Jz's date and time:Sunday 18 September 2011 6:14:37.1316394877.92 PM"; } </script> </head> <body onload="d()"> <div id="t"> </div> <br> <div id="r0"> </div> h <div id="r1"> </div> m A lot easier to see now. First problem: document.getElementById("r") There is no element with an ID of "r". Quote
Byron Posted September 19, 2011 Posted September 19, 2011 Byron, it is not that problem. Okay then, you tell me why your script isn't working? Is this what your looking for? http://byrondallas.heliohost.org/temp/java-time-php.php Quote
njaohnt Posted September 19, 2011 Author Posted September 19, 2011 Yes there is xaav. Look at it again. Byron, that is what I want, but with a thing at the bottom that has the difference. Quote
Byron Posted September 20, 2011 Posted September 20, 2011 Byron, that is what I want, but with a thing at the bottom that has the difference. I really don't think this can be done since php is server side and javascript is client side. If it can, it's beyond me. Quote
Byron Posted September 20, 2011 Posted September 20, 2011 It can byron. If nobody here at helionet can show you how, try this forum. http://www.codingforums.com I'm sure if it can be done, somebody there will know how. If you come up with a solution, please post it back here in this thread. Quote
vol7ron Posted November 3, 2011 Posted November 3, 2011 QUOTE (njaohnt @ Sep 19 2011, 08:11 PM)It can byron. If nobody here at helionet can show you how, try this forum. http://www.codingforums.com I'm sure if it can be done, somebody there will know how. If you come up with a solution, please post it back here in this thread. No need to go elsewhere, I can help you out. Your problem is this line: var c = [t.getHours, t.getMinutes, t.getSeconds]; You're storing the function reference and not the result. You should call the functions (add parentheses): var c = [t.getHours(), t.getMinutes(), t.getSeconds()]; It's "NaN" because you then calculate c[0]-j[0] which translates to "t.getHours"-12 (or some other number), so when you do a calcuation of a non-number string minus a number, it'll result to NaN. if you store the result of t.getHours() in c[0], the calculation would be two numbers (eg 9-8) Note: I didn't do the work for you, I only removed the NaN bug, you'll have to debug your code to get it to work: <!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"> <head> <meta name="generator" content="HTML Tidy for Linux/x86 (vers 11 February 2007), see www.w3.org" /> <title>Time</title> <script type="text/javascript"> //<![CDATA[ function d() { var j = [ <?php echo idate("H"); ?> , <?php echo idate("i"); ?> , <?php echo idate("s"); ?> ]; var t = new Date(); var c = [t.getHours(), t.getMinutes(), t.getSeconds()]; var a = [c[0] - j[0], c[1] - j[1], c[2] - j[2]]; var b = "After Ours"; if (a[0] < 0) { a[0] = j[0] - c[0]; b = "Before Ours"; } if (a[1] < 0) a[1] = j[1] - c[1]; if (a[2] < 0) a[2] = j[2] - c[2]; for (i = 0; i < 3; i++) document.getElementById("r" + i).innerHTML = a[0]; document.getElementById("r").innerHTML = b; document.getElementById("t").innerHTML = "Your computer's date and time:" + Date() + "<br>Our date and time:<?php $aop=" AM "; if (idate('H')>12) $aop=" PM "; $dow=array("Sunday ","Monday ","Tuesday ","Wednesday ","Thursday ","Friday ","Saturday "); $mow=array("",'January','February','March','April','May','June','July','August','September','October','November','December'); $min=idate("i"); $sec=idate("s"); if ($min<10) $min="0".idate("i"); if ($sec<10) $sec=" 0 ".idate("s"); $d=array($dow[idate('w')],idate('d'),$mow[idate('m')],idate('Y'),idate('h'),$min,$sec,microtime(get_as_float),$aop); echo $d[0]."".$d[1]."".$d[2]."".$d[3]."".$d[4].": ".$d[5].": ".$d[6].".".$d[7]."".$d[8]; ?>"; } //]]> </script> </head> <body onload="d()"> <div id="t"></div><br /> <div id="r0"></div>h <div id="r1"></div>m <div id="r2"></div>s <div id="r"></div><button onclick="window.location.href='servertime.php'">Update Time</button> </body> </html> Quote
Krydos Posted November 4, 2011 Posted November 4, 2011 Thanks for the contribution. This was probably worth digging up an old thread for. Quote
vol7ron Posted November 4, 2011 Posted November 4, 2011 Thanks for the contribution. This was probably worth digging up an old thread for. Are you stalking my posts? lol. really, these old threads are the most recent threads. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.