Welcome Guest, Not a member yet? Register   Sign In
local to gmt function doesn't work
#9

(This post was last modified: 07-13-2017, 02:32 AM by Martin7483.)

First, I think you misread my post. I did the var_dump WITHIN the function NOW()
and not from where I was calling the function

Second:
After some searching I found this on Stack Overflow

Quote:To convert a string representation of a time into a time_t value, use strtotime. If the string contains a time zone reference, strtotime will do the conversion for you. If not, you can use date_default_timezone_set to tell PHP what timezone to use when interpreting the string.

So when converting a local time to GMT time, the date time string that is converted to a timestamp should have the timezone included when using strtotime().

If the timezone is not present when using strtotime, strtotime will use the default timezone of the server.

When you use NOW(), you are asking for the current date and time for the set timezone.
Converting that value to GMT makes no sence, because it will return the current GMT
To get the current GMT time, just call local_to_gmt() without passing a value to the function

To convert a stored date time to GMT see this example
PHP Code:
// If your local date is
$date "2015-04-13 09:22:23";
// If you want to know what the GMT was at that time, append the timezone and convert to a UNIX timestamp
$local_time strtotime($date ." ".config_item('time_reference'));
// Then use local_to_gmt to get the GMT
$gmt_date date('Y-m-d H:i:s'local_to_gmt($local_time)); 

Hope my explanation is clear
Reply


Messages In This Thread
local to gmt function doesn't work - by ardavan - 07-11-2017, 06:41 AM
RE: local to gmt function doesn't work - by Martin7483 - 07-13-2017, 02:31 AM



Theme © iAndrew 2016 - Forum software by © MyBB