mouli Posted June 19, 2007 Share Posted June 19, 2007 I have several sites that use the date function to write the local date and time in New Zealand to the page. This worked fine until I moved all my sites to a server in another time zone (the USA). I need to continue writing the New Zealand date and time to the page, not local USA time. I'm aware that I can apply a time zone offset to the output of the date function but I'm not sure that this can compensate for local summer time changes etc. The way I'd like to do it is to get the date and time from a server in the original time zone (New Zealand) so it is always accurate. Has anybody got any ideas how I might achieve this or suggest a better way to do this? Many thanks Quote Link to comment Share on other sites More sharing options...
Dragen Posted June 19, 2007 Share Posted June 19, 2007 the dat() function only gets the time and date from the server it's on. If the server is in America, then the time will be American. I think that the time offset is your best option. Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted June 19, 2007 Share Posted June 19, 2007 you have certainly raised an interesting question. you can get the time for different timezones using Javascript, But I don't know if you could implement it into your current coding. Heres an example of getting the time in Tokyo. and the time of UTC. <script type="text/javascript"> // create a new Date object var now = new Date(); // store local time - in this case Tokyo, Japan var jpn = "Tokyo Time:\n" +now.toString()+ "\n\n"; // store GMT time var gmt = "UTC Time:\n" + now.toGMTString(); // display Local time and GMT time alert(jpn + gmt); </script> just an example of how it can be done. Regards ACE Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted June 19, 2007 Share Posted June 19, 2007 you can use timezones in php too... You can either have people store there favoured time zone Or (more intensive) use something lie kgeoip to detect wher ethey are automatically. Factor the result into yout date/time function use. Quote Link to comment Share on other sites More sharing options...
mouli Posted June 19, 2007 Author Share Posted June 19, 2007 Thanks for that, there is some good food for thought. I'll have play around and post my results. thanks again for your time. Quote Link to comment Share on other sites More sharing options...
mouli Posted June 24, 2007 Author Share Posted June 24, 2007 I've got a page on a new zealand server that, when called generates the unix time stamp on that server. So in effect I have a URL that returns the time stamp. Any idea how I can use this in a page in the USA to allow me to manipulate the timestamp.? How do I call the URL so I can get my spanners on the timestamp? Many thanks mouli Quote Link to comment Share on other sites More sharing options...
chigley Posted June 24, 2007 Share Posted June 24, 2007 Use this: <?php putenv("TZ=Australia/Sydney"); ?> Look here for a list of other Australian timezone options: http://www.php.net/manual/en/timezones.australia.php Quote Link to comment Share on other sites More sharing options...
mouli Posted June 24, 2007 Author Share Posted June 24, 2007 many thanks for that suggestion. I'm not sure that it takes account of daylight savings etc though. These can result in errors of a couple of hours between a country in the northern hemisphere and one in the southern hemisphere. Quote Link to comment Share on other sites More sharing options...
chigley Posted June 24, 2007 Share Posted June 24, 2007 Your server will already know if it is daylight saving or not, so that solution should work. Have you tested it? Quote Link to comment Share on other sites More sharing options...
mouli Posted June 24, 2007 Author Share Posted June 24, 2007 Hi No I haven't tested that solution yet. I think it maybe works with php5 only. I'm using php4.4. I'm also not sure how it allows for daylight saving on a server in the remote time zone. Of course it knows its local time including DLS but does a server in USA know what the actual time is in Auckland new zealand. I have access to a server in NZ so I'm working on a simple solution that includes a page on the NZ server that returns the NZ timestamp, then I can easily echo NZ time, date etc. Thanks for yur help mouli Quote Link to comment 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.