Jessica Posted May 12, 2006 Share Posted May 12, 2006 I've been trying to find a javascript clock, and all the ones I find by googling are in forms in the input field type. Does anyone know how I would do this without putting it in a form? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/9549-clock-not-in-form-box/ Share on other sites More sharing options...
eXtaZa Posted May 13, 2006 Share Posted May 13, 2006 Are you meaning this:[code]<html><head><script type="text/javascript">function startTime(){var today=new Date()var h=today.getHours()var m=today.getMinutes()var s=today.getSeconds()// add a zero in front of numbers<10m=checkTime(m)s=checkTime(s)document.getElementById('txt').innerHTML=h+":"+m+":"+st=setTimeout('startTime()',500)}function checkTime(i){if (i<10) {i="0" + i} return i}</script></head><body onload="startTime()"><div id="txt"></div></body></html>[/code]? Quote Link to comment https://forums.phpfreaks.com/topic/9549-clock-not-in-form-box/#findComment-35472 Share on other sites More sharing options...
Jessica Posted May 13, 2006 Author Share Posted May 13, 2006 That'll do the trick! Is it going off my server time or the user's computer's time? Quote Link to comment https://forums.phpfreaks.com/topic/9549-clock-not-in-form-box/#findComment-35511 Share on other sites More sharing options...
eXtaZa Posted May 13, 2006 Share Posted May 13, 2006 I think that by the user's computer time... [img src=\"style_emoticons/[#EMO_DIR#]/unsure.gif\" style=\"vertical-align:middle\" emoid=\":unsure:\" border=\"0\" alt=\"unsure.gif\" /]But I don't know exacly... Quote Link to comment https://forums.phpfreaks.com/topic/9549-clock-not-in-form-box/#findComment-35516 Share on other sites More sharing options...
Jessica Posted May 13, 2006 Author Share Posted May 13, 2006 [!--quoteo(post=373545:date=May 13 2006, 12:32 PM:name=eXtaZa)--][div class=\'quotetop\']QUOTE(eXtaZa @ May 13 2006, 12:32 PM) [snapback]373545[/snapback][/div][div class=\'quotemain\'][!--quotec--]I think that by the user's computer time... [img src=\"style_emoticons/[#EMO_DIR#]/unsure.gif\" style=\"vertical-align:middle\" emoid=\":unsure:\" border=\"0\" alt=\"unsure.gif\" /]But I don't know exacly...[/quote]yeah..it is the user's. My fiance is trying to help me get it to display server time, or at least just the same time for everyone, we want it in CST. :( Quote Link to comment https://forums.phpfreaks.com/topic/9549-clock-not-in-form-box/#findComment-35518 Share on other sites More sharing options...
eXtaZa Posted May 13, 2006 Share Posted May 13, 2006 You can use the date funtion in php, its by the server time and its much more simple... Quote Link to comment https://forums.phpfreaks.com/topic/9549-clock-not-in-form-box/#findComment-35525 Share on other sites More sharing options...
Jessica Posted May 13, 2006 Author Share Posted May 13, 2006 [!--quoteo(post=373554:date=May 13 2006, 01:21 PM:name=eXtaZa)--][div class=\'quotetop\']QUOTE(eXtaZa @ May 13 2006, 01:21 PM) [snapback]373554[/snapback][/div][div class=\'quotemain\'][!--quotec--]You can use the date funtion in php, its by the server time and its much more simple...[/quote]but then the clock isn't dynamic. Quote Link to comment https://forums.phpfreaks.com/topic/9549-clock-not-in-form-box/#findComment-35527 Share on other sites More sharing options...
Jessica Posted May 13, 2006 Author Share Posted May 13, 2006 [code]<div id="clock"><script language="javascript"> // Get the server time and GMT offset var server_offset = <? print(date('Z')); ?>; var server_time = <? print(time()); ?>; // The clock DIV var clock = document.getElementById("clock"); // Get the client GMT offset var client_offset = new Date(); client_offset = client_offset.getTimezoneOffset() / 60; // Get the appropriately mapped time var client_time = server_time; var clock = document.getElementById("clock"); var client_time = server_time; function js_clock() { var date_time = new Date((client_time * 1000)); var date = date_time.getDate(); var month = date_time.getMonth() + 1; var year = date_time.getFullYear(); var hours = date_time.getHours()+(client_offset-5); var minutes = date_time.getMinutes(); var seconds = date_time.getSeconds(); var suffix = "AM"; if(hours > 11){ suffix = "PM"; hours = hours - 12; } if(hours == 0){ hours = 12; } if(hours < 10){ hours = "0" + hours; } if(minutes < 10){ minutes = "0" + minutes; } if(seconds < 10){ seconds = "0" + seconds; } if(month < 10){ month = "0" + month; } clock.innerHTML = hours + ":" + minutes + ":" + seconds + " " + suffix; client_time++; setTimeout("js_clock()", 1000); } js_clock();</script></div>[/code]This is what I got, I checked it by setting my computer timezone differently and it works. Quote Link to comment https://forums.phpfreaks.com/topic/9549-clock-not-in-form-box/#findComment-35531 Share on other sites More sharing options...
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.