开发者

Changing Default TimeZone in Php

I have my server hosted in US and i want my php script to follow uk t开发者_如何学Cimezone , so what i did is i changed the timezone by using php timezone function desscribed below

date_default_timezone_set("Europe/London");

It works fine on my wamp server but when i upload files to my remote server it is ignoring this function and using the default time of US.

What i found is my server is using php4 and this function works on php5 or higher so is there any other way to deal with php4

Thank You


Changing the timezone with PHP was added in version 5.1, so any attempt to try and change PHP 4's timezone without custom time functions is not possible.

Your best bet is to switch to a modern hosting provider that regularly updates PHP, or get yourself a server, in my opinion Rackspace have amazing prices while LiquidWeb have amazing support, that way you can run the exact versions of server software you want.

However if you absolutely want to stick with PHP4, you would need to create custom time functions, for example:

function gmt_time()
{
    // Return time minus current timezone second offeset
    return time() - date("Z", time());
}

function my_time($offset = 0)
{
    // Return GMT time + offset hours
    return gmt_time() + ($offset * 60 * 60);
}

echo date("g:iA, l jS F Y", my_time(11)); // GMT +11 time.

However, please note that usage of the timezone parameters in the date() function such as Z, T, P and so on will not change.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜