Jump to content

Getting Correct Time-Zone - Php.ini? .htaccess?


wilsea
 Share

Recommended Posts

I'm using $page->created and $page->modified to track  the time users start and finish an activity.  No problem on localhost, but  now that it's on a server there's a 14 hour time difference. 

I figure there must be  a neater fix than adding 14 hours to each record as it is read or created.

PW config file already has $config->timezone = 'Australia/Queensland';

I've tried adding  date.timezone = "Australia/Queensland" to a php.ini file in a directory above my PW project - no change.

Tried adding the same line to PW .htaccess file - and ended up with a 404 until I removed the apparently offending line.

Any suggestions anyone?

Link to comment
Share on other sites

You could check via phpinfo() what the value of the "Loaded Configuration File" is. This will point you to the active .ini file. Also, you can check double check the current default timezone on the phpinfo page (search for "Default timezone")

After you set date.timezone in the correct .ini file i think you need to restart Apache for the change to take effect, or contact your webhoster to do this for you.

If that still does not work maybe the value is overridden by some additional .ini files that are parsed. Another thing you could try is date.timezone with single quotes or no quotes.

Link to comment
Share on other sites

Not really sure if this helps your problem or not (I think maybe not), but is your server in a timezone 14 hours away from QLD? If you need to convert from that to QLD time, you can use a function like this:

function convert_time_zone($date_time, $from_tz, $to_tz){
    $time_object = new DateTime($date_time, new DateTimeZone($from_tz));
    $time_object->setTimezone(new DateTimeZone($to_tz));
    return $time_object->format('Y-m-d H:i:s');
}

then call like this:

$qld_time = convert_time_zone($page->created, 'Other/Timezone', 'Australia/Queensland');
  • Like 1
Link to comment
Share on other sites

Thankyou all for the suggestions.

Although I've tried changing the setting from $config->timezone = 'Australia/Queensland'; to  $config->timezone = 'America/New_York';  it doesn't seem to make any difference - I guess all that is doing is setting the default value for timezone conversions to start from

On thinking it over I think I'm going to need to convert the time with a function as suggested by Adrian  - I can't be sure that all my users will be in the one timezone so config settings, php.ini  and the like won't be appropriate. 

I've tried Adrian's convert_time_zone function  and get an error    

Failed to parse time string (1405881074) at position 8 (7): Unexpected character .....

and the line number is the first line of the function ie

$time_object = new DateTime($date_time, new DateTimeZone($from_tz));

I think maybe DateTime is expecting the $date_time to be in format '2007-11-30 10:30:19' instead of a big number string that comes from $page->created,  but that's as far as I've got with trying to the convert_time_zone function  working.

Need more guru help please.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...