在 PHP 中更改默认时区 [英] Changing Default TimeZone in Php

查看:26
本文介绍了在 PHP 中更改默认时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的服务器托管在美国,我希望我的 php 脚本遵循英国时区,所以我所做的是使用下面描述的 php 时区函数更改时区

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");

它在我的 wamp 服务器上运行良好,但是当我将文件上传到我的远程服务器时,它会忽略此功能并使用美国的默认时间.

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.

我发现我的服务器正在使用 php4 并且此功能适用于 php5 或更高版本,所以还有其他方法可以处理 php4

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

谢谢

推荐答案

使用 PHP 更改时区是在 5.1 版本中添加的,因此任何尝试在没有自定义时间函数的情况下更改 PHP 4 时区的尝试都是不可能的.

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.

您最好的选择是切换到定期更新 PHP 的现代托管服务提供商,或者让自己拥有一台服务器,在我看来,Rackspace 的价格非常优惠,而 LiquidWeb 的支持却很棒,这样您就可以运行您想要的服务器软件的确切版本想要.

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.

但是,如果您绝对想坚持使用 PHP4,则需要创建自定义时间函数,例如:

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.

但是请注意date()函数中时区参数的用法,如Z、T、P等不会改变.

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

这篇关于在 PHP 中更改默认时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆