Jump to content

Set Exact Est Timezone How?


lovephp

Recommended Posts

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

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.