wamp修改默认时区_更改PHP默认时区

wamp修改默认时区

Every installation of makes an assumption about where it is on planet Earth. PHP does not read the location information from the computer it is installed on: that would be the role of JavaScript. Instead, every web server installation defaults to a pre-determined timezone. It is likely that this default won’t match the actual physical location of the server. For example, if you’ve downloaded and installed XAMPP, the server assumes its local timezone is Berlin, Germany.

每次安装都会假设它在地球上的位置。 PHP 读它安装在计算机中的位置信息:这将是角色JavaScript 。 而是,每个Web服务器安装默认为预定的时区。 此默认值很可能与服务器的实际物理位置不匹配。 例如,如果您下载并安装了XAMPP ,则服务器将假定其本地时区为德国柏林。

This can be confusing, especially when using the date() function on a PHP page – date("Y") will obviously provide the right year 99.99% of the time, but date('l’) (a lowercase L, to generate the name of the day) will sometimes be right for your location (when Germany happens to be in the same day) and sometimes not (when Germany is one day ahead of you)*.

这可能会造成混淆,尤其是当在PHP页面上使用date()函数时– date("Y")显然会提供正确的年份99.99%的时间,但是date('l') (小写的L,用于生成一天的名称)有时会适合您的位置(德国碰巧在同一天),有时又不适合您(当德国比您晚一天时) *

While you can look through the php.ini file or phpinfo() to locate the default timezone information, most people will probably find it easier to display it on a PHP page with a temporary line of code:

虽然您可以浏览php.ini文件或phpinfo()来查找默认时区信息,但是大多数人可能会发现,使用临时代码行将其显示在PHP页面上更为容易:

<?php echo date_default_timezone_get(); ?>

This will provide you with the geographical area that PHP assumes it is located in. Note that this information is provided in the format city/region. If "America" is referred to, it includes the entire continent, from the frozen north of Nunavut to Tierra del Fuego. Also note that the city location references the primary or capital city of the area, and does not recognize inter-city or national rivalries, so (for example) the correct timezone for Alberta is Edmonton, America.

这将为您提供PHP假定其所在的地理区域。请注意,此信息以city / region格式提供。 如果提到“美洲”,则包括从冰冻的努纳武特北部到火地岛的整个大陆。 另请注意,城市位置是指该地区的主要城市或首都,并且不识别城市间或国家间的竞争,因此(例如)艾伯塔省的正确时区是美国埃德蒙顿

If the timezone displayed on this test page is not correct, you can try editing the server’s php.ini file, but this may not be possible in a hosted web environment. Most people will find it easier to correct the timezone on the PHP page itself, before you calculate a date or time.

如果此测试页上显示的时区不正确,则可以尝试编辑服务器的php.ini文件,但是在托管的Web环境中可能无法实现。 在计算日期或时间之前,大多数人会发现更容易在PHP页面上更正时区。

For any PHP5 script that needs to reference the exact local time on a server with an incorrect timezone, before you use any date or time functions, write:

对于需要使用不正确的时区的服务器上需要引用确切本地时间的任何PHP5脚本, 使用任何日期或时间函数之前,请编写:

<?php date_default_timezone_set('America/Edmonton'); ?>

(php.net has a complete list of PHP timezone values: find the one nearest and most relevant to you, replacing 'America/Edmonton' with the appropriate location).

( php.net包含PHP时区值完整列表 :找到与您最接近,最相关的一个,将'America/Edmonton'替换为适当的位置)。

If you follow this line with echo date_default_timezone_get() you’ll find that the timezone is now correct, as are all calculated dates. You just have to remember to start any page that uses PHP-generated time or date values with this line. It’s not unusual to ensure this by making it part of an include for every page:

如果在此行中echo date_default_timezone_get()您将发现时区现在正确,所有计算出的日期也正确。 您只需要记住在此行中启动任何使用PHP生成的时间或日期值的页面。 通过将其作为每个页面的include内容的一部分来确保这一点并不罕见:

<? date_default_timezone_set('America/Edmonton'); ?>
<!DOCTYPE html>
<head>

With this in place, confusing time results in PHP should be a thing of the past.

有了这一点,混淆时间导致PHP应该已经成为过去。

翻译自: https://thenewcode.com/519/Changing-the-PHP-Default-Timezone

wamp修改默认时区

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值