Forum Moderators: coopster
<?php
echo date("G:i");
?>
to display as: 20:09
but is there any way that I can display the time for another timezone?
I'm wanting to display the time for a few different countries like this:
London: 20:09
New York: 15:09
Sydney: 07:11
Is there any way of doing this simply?
Yes there are ways of doing it something like this:-
I'm approximating the time because I dont know the exact differences but hopefully you can see the mechanics of it.
$new_york_time = "New york: ".date("G:i", strtotime(" + 5 hours"));
$Tokyo_time = "Tokyo: ".date("G:i", strtotime(" + 8 hours"));
$sydney_time = "Sydney: ".date("G:i", strtotime(" + 11 hours"));
just echo the vars from there
From what I understand the strtotime can be used as an offset, I havnt tried this code but as long as its concatonated you should be ok. I use a version of this as my server time stamp and have to alter it by a few hours, if you want this to do the same thing from any terminal on the planet I dont think it would work, this is relative to the server that the php is being executed on.
Hope that makes sense, either way have a play and you should find some combination that will work.
Cheers,
MRb
I have this:
<?php
$new_york_time = "New york: ".date("G:i", strtotime(" - 5 hours"));
echo "$new_york_time";
?>
which is showing correctly in the UK but I would think if you looked at this in a country that is not currently showing GMT then it wouldn't be correct?
If you are running PHP5, look into date_default_timezone_set [php.net] which enables you to set the default timezone for your script. You can find a list of supported timezones here [php.net].
If you want users to see the time in their own zone, you`ll have to provide the user with a time adjustment feature and set a cookie on the users machine. Like many message boards have. The PHP website provides all the info you should need with regards to Date & Time Functions [php.net].
dc