peranha Posted October 24, 2008 Share Posted October 24, 2008 How do you get the server time in real time, so it updates every second and display the date, time on the page. I was thinking javascript, but it is client side, not server side, so I dont believe this will work. I want it to display like this MM/DD/YYYY H:M:S Quote Link to comment https://forums.phpfreaks.com/topic/129980-solved-server-time/ Share on other sites More sharing options...
zq29 Posted October 24, 2008 Share Posted October 24, 2008 XMLHttpRequest? Quote Link to comment https://forums.phpfreaks.com/topic/129980-solved-server-time/#findComment-673856 Share on other sites More sharing options...
steelmanronald06 Posted October 24, 2008 Share Posted October 24, 2008 Use AJAX to call the time() function. http://www.billwelense.com/depaul/ajaxdemo/demo.html Quote Link to comment https://forums.phpfreaks.com/topic/129980-solved-server-time/#findComment-673934 Share on other sites More sharing options...
peranha Posted October 24, 2008 Author Share Posted October 24, 2008 Thanks, ended up using Ajax. Quote Link to comment https://forums.phpfreaks.com/topic/129980-solved-server-time/#findComment-673994 Share on other sites More sharing options...
Stooney Posted October 25, 2008 Share Posted October 25, 2008 A less resource intensive way would be to use a javascript clock and have php set the current time initially. Quote Link to comment https://forums.phpfreaks.com/topic/129980-solved-server-time/#findComment-674219 Share on other sites More sharing options...
waynew Posted October 25, 2008 Share Posted October 25, 2008 I'm with Chris on that one. Quote Link to comment https://forums.phpfreaks.com/topic/129980-solved-server-time/#findComment-674419 Share on other sites More sharing options...
dropfaith Posted October 25, 2008 Share Posted October 25, 2008 Js would be easier but its not Server time i think he wanted server time for some reason Js way <div id="digitalclock" style="float:left;width:400px;"><script language="javascript">calctime();</script></div> function calctime() { var currenttime = new Date(); var day = currenttime.getDay(); var hours = currenttime.getHours(); var minutes = currenttime.getMinutes(); var seconds = currenttime.getSeconds(); var day = currenttime.getDay(); var month = currenttime.getMonth(); var weekday= currenttime.getDate(); var year= currenttime.getYear(); if (year < 2000) year = year + 1900; hours = currenttime.getHours(); if (hours >= 12) { hours = (hours == 12) ? 12 : hours - 12; timesuffix = " PM"; } else { hours = (hours == 0) ? 12 : hours; timesuffix = " AM"; } if (minutes < 10) { minutes = "0" + minutes; } if (seconds < 10) { seconds = "0" + seconds; }; arday = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday") armonth = new Array("January ","February ","March ","April ","May ","June ","July ","August ","September ", "October ","November ","December ") ardate = new Array("0th","1st","2nd","3rd","4th","5th","6th","7th","8th","9th","10th","11th","12th","13th","14th","15th","16th","17th","18th","19th","20th","21st","22nd","23rd","24th","25th","26th","27th","28th","29th","30th","31st"); var clocklocation = document.getElementById('digitalclock'); clocklocation.innerHTML = hours + ":" + minutes + ":" + seconds + " " + timesuffix + ", " + arday[day] +", " + armonth[month] +" "+ardate[weekday] + ", " + year; setTimeout("calctime()", 1000); } Quote Link to comment https://forums.phpfreaks.com/topic/129980-solved-server-time/#findComment-674423 Share on other sites More sharing options...
peranha Posted October 25, 2008 Author Share Posted October 25, 2008 Yes, I wanted server time so when updates are done, there is a clock on the webpage, and I can say at 2:00 server time updates will be done. Quote Link to comment https://forums.phpfreaks.com/topic/129980-solved-server-time/#findComment-674437 Share on other sites More sharing options...
waynew Posted October 25, 2008 Share Posted October 25, 2008 IF you're telling your user that an update WILL BE DONE at a certain time, you might want to just use JavaScript. That way, you can relate it to their timezone as the JS will use the time on their computer. Quote Link to comment https://forums.phpfreaks.com/topic/129980-solved-server-time/#findComment-674482 Share on other sites More sharing options...
steelmanronald06 Posted October 25, 2008 Share Posted October 25, 2008 Yes, but then he has to figure in timezone manipulation for each user. Oh, the javascript says this users time is this. That relates to the server time like so, thus the updates will be done at this time (in users time zone). His way says: Here is what time it is at our server location: ##:## Here is when the updates will be done in relation to our server time: ##:## Quote Link to comment https://forums.phpfreaks.com/topic/129980-solved-server-time/#findComment-674617 Share on other sites More sharing options...
peranha Posted October 25, 2008 Author Share Posted October 25, 2008 Yes, but then he has to figure in timezone manipulation for each user. Oh, the javascript says this users time is this. That relates to the server time like so, thus the updates will be done at this time (in users time zone). His way says: Here is what time it is at our server location: ##:## Here is when the updates will be done in relation to our server time: ##:## exactly, I have on my server Server time is 10/25/2008 6:21 PM An update will be done on 10/25/2008 6:21 PM Quote Link to comment https://forums.phpfreaks.com/topic/129980-solved-server-time/#findComment-674719 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.