Changing Default TimeZone in Php

僤鯓⒐⒋嵵緔 提交于 2019-12-11 01:49:50

问题


I have my server hosted in US and i want my php script to follow uk timezone , 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


回答1:


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.



来源:https://stackoverflow.com/questions/7709458/changing-default-timezone-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!