FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PHP time





Dougie1
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. Very Happy
mathiaus
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;
powers1983
I was trying to find something that did this too - but was able to do it automatically.

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.
powers1983
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.
fromegame
Code:
putenv('TZ=Europe/Amsterdam');


Change Europe/Amsterdam to your desired city/town/country.
Related topics
http://tuvanonline.com/library/index.php
PHP-Nuke platium?
PHP Write to line
Anyone good with PHP-NUKE?
PHP safety?
req: PHP to list files in directory, and link to them
php admin and mysql admin console
Mysql And PHP HELP PLZ
Great php editor
Script php about gallery
File upload with PHP, Build an upload database for your site
[php scripts ] phpweather&email
Including With PHP
help me upgrade php to 5.
php includes
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.