How would I go about adding on 7 hours to the current time (therefore making it GMT) in php 4, (current version on frihost). I know there is a set time zone function but it only works on php 5 plus... Thanks in advance. 
PHP time
You need to work out what 7 hours is in seconds. 60 seconds in a minute, 60 minutes in an hour, 7 hours.
| Code: |
| $time = time() + 60*60*7; |
I was trying to find something that did this too - but was able to do it automatically.
This looks promising but is 10 hours behind. So it seems to be subtracting 5 hours instead of adding like it needs to.
if this is a bug then I suppose a function that calculates the difference php is applying then reverses it would work.
David.
| Code: |
|
$time_gmt=strtotime("now GMT"); |
This looks promising but is 10 hours behind. So it seems to be subtracting 5 hours instead of adding like it needs to.
if this is a bug then I suppose a function that calculates the difference php is applying then reverses it would work.
David.
| Code: |
|
function gm_time ($t) { $zone_secs = intval(date("Z")); $t -= $zone_secs; return $t; } $time_gmt=gm_time(time()); $time_gmt_string = date("D jS F Y @ h:ia", $time_gmt); |
That will display GMT time on Server 2 at least. When I get home I will make sure that it works on my machine (which is currently set at UK BST).
If it does then its easier than having to remember to change the offset each time you update your pages.
David.
| Code: |
| putenv('TZ=Europe/Amsterdam'); |
Change Europe/Amsterdam to your desired city/town/country.
