Jump to content

Calculating the GMT time difference with the time() function


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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.