Jump to content

Calculating the GMT time difference with the time() function


Demonic

Recommended Posts

Alright, its been said a few times, but I just can't get this script to work like it is supposed to work for example my current code is:

 

function timezone_stamp( $time, $gmt )
{
//check if the gmt date is empty or is the wrong gmt, set the default gmt to zero
$gmt = (empty( $gmt ) || $gmt > 12 || $gmt < -12) ? 0 : (int) $gmt;
//fix up the gmt 
$timestamp = $time + ( $gmt * 60 * 60  );

return gmdate( "m d Y h:i:sa", $timestamp );
//output the gmt to for later use
}

 

I keep getting people telling me that above works, actually it doesn't, on my home server and only server its completely incorrect.

 

Now how do I fix my code to make a basic working time stamp that actually works.

Alright now Since no one here ever helps maybe someone can now.

 

<?php
/**
*	@param - $gmt - This is the current users GMT
*	@param - $serverGMT - This is the default servers GMT
*	@param - $time - This is the current time
*/
function timestamp( $gmt, $serverGMT, $time, $dst = 0 )
{

$gmtTime = $gmt - $serverGMT;
$offset = $time + ( $gmtTime * 60 * 60 );
return date( "m d Y h:i:sa", $offset );
}

echo timestamp( -6, 5, time() );
?>

 

My script it self gets the servers time zone and my actual time zone and compare differences to get the actual offset, but what is the best way to get the servers GMT(TimeZone)?

 

http://ex-code.info/test/time.php

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.