lovephp Posted November 9, 2012 Share Posted November 9, 2012 guys our office server time is wrong so whenever i run a javascript time script on my hosting it shows wrong on my system. is there a fix that i could show time according google or something? Quote Link to comment https://forums.phpfreaks.com/topic/270521-set-exact-est-timezone-how/ Share on other sites More sharing options...
MDCode Posted November 9, 2012 Share Posted November 9, 2012 (edited) I'm not sure if it works in javascript but try the htaccess file, use the SetEnv TZ function. A full list of timezones can be found at: http://www.php.net/m...n/timezones.php Example of usage: SetEnv TZ US/Eastern Your hosting provider may or may not also restrict the changing of timezones Edited November 9, 2012 by SocialCloud Quote Link to comment https://forums.phpfreaks.com/topic/270521-set-exact-est-timezone-how/#findComment-1391391 Share on other sites More sharing options...
lovephp Posted November 9, 2012 Author Share Posted November 9, 2012 yes that i know but when it comes to javascript time scripts it shows all wrong on my computer. i just wish to show correct est time. Quote Link to comment https://forums.phpfreaks.com/topic/270521-set-exact-est-timezone-how/#findComment-1391393 Share on other sites More sharing options...
Jessica Posted November 9, 2012 Share Posted November 9, 2012 Javascript is client side. That means your computer, not the server. Quote Link to comment https://forums.phpfreaks.com/topic/270521-set-exact-est-timezone-how/#findComment-1391396 Share on other sites More sharing options...
lovephp Posted November 9, 2012 Author Share Posted November 9, 2012 how do i get a js to show only EST PST CST and MST without matching with the system as in client side?? Quote Link to comment https://forums.phpfreaks.com/topic/270521-set-exact-est-timezone-how/#findComment-1391399 Share on other sites More sharing options...
lovephp Posted November 9, 2012 Author Share Posted November 9, 2012 ok i got this <script type="text/javascript"> function myCallback(json) { document.write(new Date(json.dateString)); } </script> <script type="text/javascript" src="http://timeapi.org/utc/now.json?callback=myCallback"></script> could someone help make it to get PST CST MST and EST with it? just the time no date. thanks Quote Link to comment https://forums.phpfreaks.com/topic/270521-set-exact-est-timezone-how/#findComment-1391405 Share on other sites More sharing options...
codefossa Posted November 10, 2012 Share Posted November 10, 2012 You could do something like this. You should be able to easily just make that a function for yourself if you want it. Demo Page: http://xaotique.no-ip.org/tmp/18/ HTML <form id="myform" method="post" action="#"> <b>Hour Offset:</b> <input type="text" value="-5" id="offset" /> <input type="submit" value="Get Time" /> </form> <b>Time:</b> <span id="result"></span> Javascript window.addEventListener("load", function() { window.document.getElementById("myform").onsubmit = function(event) { event.preventDefault(); var date = new Date(); var utc = date.getTime() + (date.getTimezoneOffset() * 60000); var local = new Date(utc + (parseInt(window.document.getElementById("offset").value) * 3600 * 1000)); var newDate = local.toLocaleString(); var time = newDate.replace(/(.*)\s([0-9][0-9][^\s]*))(.*)?/, '$2'); window.document.getElementById("result").innerHTML = time; return false; } }, false); Quote Link to comment https://forums.phpfreaks.com/topic/270521-set-exact-est-timezone-how/#findComment-1391445 Share on other sites More sharing options...
lovephp Posted November 10, 2012 Author Share Posted November 10, 2012 still do not solve the issue it shows time according to cumputer Quote Link to comment https://forums.phpfreaks.com/topic/270521-set-exact-est-timezone-how/#findComment-1391533 Share on other sites More sharing options...
Jessica Posted November 10, 2012 Share Posted November 10, 2012 That's what Javascript DOES. If you want the server time you need to use PHP. Quote Link to comment https://forums.phpfreaks.com/topic/270521-set-exact-est-timezone-how/#findComment-1391552 Share on other sites More sharing options...
lovephp Posted November 10, 2012 Author Share Posted November 10, 2012 with php i can do but it is not digital. is there a way i can get the time from server with php and then make it digital with javascript? Quote Link to comment https://forums.phpfreaks.com/topic/270521-set-exact-est-timezone-how/#findComment-1391553 Share on other sites More sharing options...
Pikachu2000 Posted November 10, 2012 Share Posted November 10, 2012 What on earth are you talking about? We aren't mind readers; post an example of what you mean by "digital". Quote Link to comment https://forums.phpfreaks.com/topic/270521-set-exact-est-timezone-how/#findComment-1391556 Share on other sites More sharing options...
lovephp Posted November 10, 2012 Author Share Posted November 10, 2012 lol i was saying is it possible to make the php displayed time into digital with javascript? eg: <?php $time = date("h:i:s"); echo $time; ?> can this be made digital ? Quote Link to comment https://forums.phpfreaks.com/topic/270521-set-exact-est-timezone-how/#findComment-1391558 Share on other sites More sharing options...
Pikachu2000 Posted November 10, 2012 Share Posted November 10, 2012 \ What on earth are you talking about? We aren't mind readers; post an example of what you mean by "digital". Quote Link to comment https://forums.phpfreaks.com/topic/270521-set-exact-est-timezone-how/#findComment-1391563 Share on other sites More sharing options...
lovephp Posted November 10, 2012 Author Share Posted November 10, 2012 alright this does the job <html> <body> <script type="text/javascript"> function Ajax(){ var xmlHttp; try{ xmlHttp=new XMLHttpRequest();// Firefox, Opera 8.0+, Safari } catch (e){ try{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer } catch (e){ try{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ alert("No AJAX!?"); return false; } } } xmlHttp.onreadystatechange=function(){ if(xmlHttp.readyState==4){ document.getElementById('EST').innerHTML=xmlHttp.responseText; setTimeout('Ajax()',1); } } xmlHttp.open("GET","datetime.php",true); xmlHttp.send(null); } window.onload=function(){ setTimeout('Ajax()',1); } </script> <div id="EST"></div> </body> </html> how can i add multiple divs to add more php files to be refreshed ? Quote Link to comment https://forums.phpfreaks.com/topic/270521-set-exact-est-timezone-how/#findComment-1391583 Share on other sites More sharing options...
haku Posted November 11, 2012 Share Posted November 11, 2012 Depends on whether or not you want to do it digitally. Quote Link to comment https://forums.phpfreaks.com/topic/270521-set-exact-est-timezone-how/#findComment-1391644 Share on other sites More sharing options...
Jessica Posted November 11, 2012 Share Posted November 11, 2012 I'd love to see how you've gotten PHP to display the time analog. Quote Link to comment https://forums.phpfreaks.com/topic/270521-set-exact-est-timezone-how/#findComment-1391648 Share on other sites More sharing options...
codefossa Posted November 11, 2012 Share Posted November 11, 2012 What I gave you gives you the time as you're wanting it, and you can set it for any timezone by just changing the offset. Check the demo page I posted and you can see it work. I put -5 in as default value and it gives eastern time, and changed by an hour which ever way you move the offset. Also, calling a PHP file to update the time (assuming that's what you were talking about) is a lot more than letting it run client-sided. Quote Link to comment https://forums.phpfreaks.com/topic/270521-set-exact-est-timezone-how/#findComment-1391650 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.