Fincikas Posted August 2, 2012 Share Posted August 2, 2012 Hi, I would like to ask how to set server/website time independent of user PC time, so if person would change his computer time, time in website would stay the same, or back to the normal after reloading the page. Quote Link to comment https://forums.phpfreaks.com/topic/266605-time/ Share on other sites More sharing options...
Mahngiel Posted August 2, 2012 Share Posted August 2, 2012 do you have root server access to change the time? is it a windows or linux based server? More importantly, is changing the system time going to do what you want? No. User time is never reflected on the server. If you post a newsblog at 5pm local time, and the server is in Romania, using PHP's date and time functions will store the server's time. When you recall that time, all users will see the server's time. To get around this, many developers take a few steps: [*] Setting a "standard" time offset for the application. If you live in the east coast and your readers are typically from the same area, this would be EST (-5) / EDT (-4) [*] Users set up their own preference to time zone which creates another offset [*] When saved to the database, the newsblog's time is created to GMT (+0) [*] When recalling the timestamp from the database, if there is a logged in user with offset preference, the math is applied accordingly [*] Else, the application's standard time is used (-5 in this instance) Quote Link to comment https://forums.phpfreaks.com/topic/266605-time/#findComment-1366376 Share on other sites More sharing options...
Fincikas Posted August 2, 2012 Author Share Posted August 2, 2012 Im creating coutdown timer, so if user changes his time on PC it changes in timer too. Could you write any code to help me out, because im using default time zone ant ect. Even if its in the server(hosting) it still changes, but Im mainly working on wamp server now. It is Javascript now, but if I could set undisturbiable default server time, I know how to solve it. Code: <html> <head> <script type="text/javascript"> function cdtd() { var xmas = new Date("December 25, 2012 00:01:00"); var now = new Date(); var timeDiff = xmas.getTime() - now.getTime(); if (timeDiff <= 0) { clearTimeout(timer); document.write("Christmas is here!"); // Run any code needed for countdown completion here } var seconds = Math.floor(timeDiff / 1000); var minutes = Math.floor(seconds / 60); var hours = Math.floor(minutes / 60); var days = Math.floor(hours / 24); hours %= 24; minutes %= 60; seconds %= 60; document.getElementById("daysBox").innerHTML = days; document.getElementById("hoursBox").innerHTML = hours; document.getElementById("minsBox").innerHTML = minutes; document.getElementById("secsBox").innerHTML = seconds; var timer = setTimeout('cdtd()',1000); } </script> </head> <body> Days Remaining: <div id="daysBox"></div> Hours Remaining: <div id="hoursBox"></div> Minutes Remaining: <div id="minsBox"></div> Seconds Remaining: <div id="secsBox"></div> <script type="text/javascript">cdtd();</script> </body> </html> BTW thanks for help Quote Link to comment https://forums.phpfreaks.com/topic/266605-time/#findComment-1366395 Share on other sites More sharing options...
Mahngiel Posted August 2, 2012 Share Posted August 2, 2012 Could you write any code to help me out No. That's not what these forums are for. I'm certain once a mod moves this to the proper home somebody will help you with that though. Quote Link to comment https://forums.phpfreaks.com/topic/266605-time/#findComment-1366399 Share on other sites More sharing options...
Fincikas Posted August 3, 2012 Author Share Posted August 3, 2012 Could you write any code to help me out No. That's not what these forums are for. I'm certain once a mod moves this to the proper home somebody will help you with that though. SO what are these forums for? Just type some not understandable sentences that PHP master can understand, and u left us beginners alone. You call that help? Ok if you can give me a code, please explain some steps that u wrote before... Quote Link to comment https://forums.phpfreaks.com/topic/266605-time/#findComment-1366525 Share on other sites More sharing options...
requinix Posted August 3, 2012 Share Posted August 3, 2012 phpfreaks in general is for helping you do stuff. If you want someone to do it for you then try the Freelancing forum. And be prepared to hand over some money. a) Why does it matter if the user gets the timer to expire? It's just JavaScript. b) Start with the date difference and subtract 1 each second: if the date changes on the client it won't matter. Quote Link to comment https://forums.phpfreaks.com/topic/266605-time/#findComment-1366531 Share on other sites More sharing options...
Mahngiel Posted August 3, 2012 Share Posted August 3, 2012 SO what are these forums for? Just type some not understandable sentences that PHP master can understand, and u left us beginners alone. You call that help? Ok if you can give me a code, please explain some steps that u wrote before... Your sentences are incoherent and you haven't written an ounce of PHP. You have Javascript here and Requinix has given you the advice you sought. You should say thank you Quote Link to comment https://forums.phpfreaks.com/topic/266605-time/#findComment-1366571 Share on other sites More sharing options...
Fincikas Posted August 3, 2012 Author Share Posted August 3, 2012 Ok, thank you. But I dont understand this: Start with the date difference and subtract 1 each second: if the date changes on the client it won't matter. How to get date difference? Difference with what? User and server time? How to subtract and from what? From difference? from time? Sorry for my nobeish, sorry for my flame, sorry I dont red rules and ect. but I stuck with this for weeks, Im trying to solve it and cant. And when i joined PHP/Javascript masters forum and they couldnt explain for total noob a thing Im anoyed, so please explain it in detail, no need to write code, but more detailed. THANK YOU Quote Link to comment https://forums.phpfreaks.com/topic/266605-time/#findComment-1366610 Share on other sites More sharing options...
requinix Posted August 4, 2012 Share Posted August 4, 2012 Unix timestamps are easiest. var diff = - new Date().getTime(); var interval = window.setInterval(function() { console.log("" + diff + " seconds left..."); if (--diff window.clearInterval(interval); } }, 1000); Quote Link to comment https://forums.phpfreaks.com/topic/266605-time/#findComment-1366698 Share on other sites More sharing options...
Fincikas Posted August 4, 2012 Author Share Posted August 4, 2012 Im pretty good at PHP, but JavaScript code I got from internet (just copy pasted) and I dont know anything about that , but still thanks for the code and for Unix timestamp name, cause I can start googleing something useful, but if you would mind to save my time and explain where to put, or just to say should I anything put in /* future timestamp */. Quote Link to comment https://forums.phpfreaks.com/topic/266605-time/#findComment-1366796 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.