Page 1 of 1

Date and time

Posted: Mon Jan 15, 2007 9:44 am
by amir
Hello,

We have different date and time functions to get server date and time but is there any way in PHP that we could display date and time of a specific place?

For example, if I want to get current date and time of Toronto, Canada. How can I do that?

Any help would be greatly appreciated.

TIA!
Joke: Some might think that first I should know about a server which is in Toronto, Canada and then I should have my site on that server.
:D

Posted: Mon Jan 15, 2007 9:57 am
by feyd
Create a timestamp that is a central location (like GMT) then adjust that time to the timezone you wish to display.

Posted: Mon Jan 15, 2007 9:57 am
by pickle
As far as I know, there's no function that accepts 'Toronto, Canada' as arguments. I think the best you can do is use gmdate() to get the GMT time, then use strtotime() to apply the offset to get the time in Toronto (-5 I think).

Posted: Mon Jan 15, 2007 10:13 am
by amir
Please advise!

I can calculate toronto canada time by my server time minus toronto canada's time. Is it a proper technique?

For example, my server time is
Current Server Time:9:10:53 PM (Mon)
and I know the current toronto canada time is
Monday, January 15, 2007 at 11:11:53 AM EST

and if minus 600 minutes from my server time then I get the date and time of toronto canada time.

Is it OK? if not how can I make it OK.
Thanks.

Posted: Mon Jan 15, 2007 10:25 am
by volka
If you have php 5.2

Code: Select all

$tz = timezone_open('America/Toronto');
$dt = date_create('now', $tz);
echo $dt->format(DATE_RFC822);
will do.

Posted: Mon Jan 15, 2007 12:36 pm
by amir
what about this one?

Code: Select all

echo 'Current time in Toronto: ' . date('m/d/Y H:i:s', time() - date('Z') + -5 * 3600);
Thanks!

Posted: Mon Jan 15, 2007 6:18 pm
by volka
I'd rather use the zoneinfo, like in java, c# and many more. But it might take a while until php 5.2+ is standard ;)

Posted: Tue Jan 16, 2007 3:46 am
by classic037
hey,

try this..

Code: Select all

<?
echo "Original Time: ". date("h:i:s")."\n";
putenv("TZ=US/Eastern");
echo "New Time: ". date("h:i:s")."\n";
?>
find valu for Toronto, Canada in putenv function... like


find time zone(TZ) list in given url:
http://www.theprojects.org/dev/zone.txt