Forum Moderators: coopster

Message Too Old, No Replies

PHP and time according to GMT

         

toplisek

11:46 am on Jan 7, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I like to define time (date) with GMT variable. I try to do it with code like:
PHP Code:

<?PHP $dat = mktime(date("G"), date("i"), date("s"), date("n"), date("j"), date("Y"));
$difference = substr(date("O",$dat),1,2);
$datdif = 60 * 60 * $difference;


if (substr(date("O",$dat),0,1) == '+') {
$dat = $dat - $datdif;
}
else {
$dat = $dat + $datdif;
}

echo date("H:i:s", $dat);//Output
?>
How to define GMT variable to work for all time zones as separate variable?

This works for London time.

coopster

4:07 pm on Jan 14, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Are you aware of the GMT mktime function? gmmktime [php.net]

toplisek

6:37 pm on Jan 14, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I try to set correctly different server time and different local time to user.

$timezone = date_default_timezone_set("Europe/London");//Sets the default time zone for local time NOT server

function myDate( $format, $timestamp, $timezone){
print myDate( 'h:s a', time() );//calling this would output the current local time
echo '<br>'.strftime('%T GMT',gmmktime()).', timestamp='.gmmktime();
//echo 18:52:08 GMT, timestamp=1076457128

}

Is this correct function for time?

toplisek

6:55 pm on Jan 19, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Will this work in correct way?

g1smd

7:44 pm on Jan 19, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Be aware that London time is NOT GMT all year round.

In the UK winter, London time is GMT.

In the UK summer, London time is GMT+1.

toplisek

8:27 am on Jan 20, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Is there some nice example for time stamp according to timezones?

Matthew1980

8:39 am on Jan 20, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi all,

Try the manual [php.net] for the different settings that you can have [php.net]

Cheers,
MRb