在 PHP 中更改时区 [英] Changing timezone in PHP

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

问题描述

好的,快速提问.

服务器在东部时间运行.PHP 程序需要使用中央时间进行日期计算.

A server is running in Eastern Time. PHP program needs to make date calculations using Central time.

目前,我将此行放在脚本的最顶部:

At the moment, I am putting this line at the very top of my script:

putenv("TZ=US/Central");

这是最好的方法还是有一些我不知道的 PHP 技巧?

Is that the best way to go about that or is there some PHP trick I'm not aware of?

干杯.

推荐答案

您可以使用 date_default_timezone_set 并且脚本中的所有日期/时间函数都将使用它.

You can use date_default_timezone_set and all the date/time functions in the script will use it.

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

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