Jump to content

Recommended Posts

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 by SocialCloud

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

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

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 ?

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.

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.