Demonic Posted February 5, 2008 Share Posted February 5, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/89468-calculating-the-gmt-time-difference-with-the-time-function/ Share on other sites More sharing options...
Demonic Posted February 5, 2008 Author Share Posted February 5, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/89468-calculating-the-gmt-time-difference-with-the-time-function/#findComment-458265 Share on other sites More sharing options...
haku Posted February 5, 2008 Share Posted February 5, 2008 $server_time_zone = date("Z",time()); Quote Link to comment https://forums.phpfreaks.com/topic/89468-calculating-the-gmt-time-difference-with-the-time-function/#findComment-458394 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.