Welcome Guest, Not a member yet? Register   Sign In
Timezone Convertion Problem
#1

[eluser]Unknown[/eluser]
Code:
$tz = 'UM5';
$dst = TRUE;

$date_str = '2010-06-04 09:00:00';
            
echo unix_to_human(gmt_to_local(convert_to_gmt(human_to_unix($date_str), $tz, $dst), $tz, $dst), TRUE, 'eu');

The above code is supposed to give output "2010-06-04 9:00:00" but it is showing "2010-06-04 11:00:00"

It is showing 2 more hours. Can anyone tell me why? Did I made any mistake?
#2

[eluser]pickupman[/eluser]
Server time is based on server location, so is your hosting/server 2 hours offset?
#3

[eluser]Unknown[/eluser]
Im not sure about the host/server offset but it occurs both in my localhost and production server. And on the above code there is no part to get date/time from system, so I think offset is not affecting here. I checked the code of the function 'gmt_to_local' and 'convert_to_gmt' and I think the code of 'convert_to_gmt' has some problem. Here is the code of the date helper:

Code:
function convert_to_gmt($time = '', $timezone = 'UTC', $dst = FALSE)
    {            
        if ($time == '')
        {
            return now();
        }
        
        $time -= timezones($timezone) * 3600;

        if ($dst == TRUE)
        {
            $time += 3600;
        }
        
        return $time;
    }

On dst calculation they are adding 3600 but I think it should be subtracted. 'gmt_to_local' is giving correct result but 'convert_to_gmt' is erroneous, Im guessing that. What do u think? Thanks for your valuable comment.
#4

[eluser]pickupman[/eluser]
On thing you could try is a simple:
Code:
echo date("Y-m-d H:i:s");

Try in both environments, and see what you come up with. You may have already tried this, but I have noticed working on various sites some host default to gmt, some local timezones, some allow you to set in php.ini.




Theme © iAndrew 2016 - Forum software by © MyBB