开发者

Handling timezones in PHP and MySQL?

开发者 https://www.devze.com 2023-02-11 15:36 出处:网络
I\'m testing out making an entry system but the problem is, my host\'s timezone is different from where I live. It\'s 3am on my server while on my local computer, the time is 4pm. How do I automatical

I'm testing out making an entry system but the problem is, my host's timezone is different from where I live. It's 3am on my server while on my local computer, the time is 4pm. How do I automatically adjust code that I pull from the database to be displayed as a timezone similar to where I'm 开发者_开发技巧at?


You can set the default timezone using the function date_default_timezone_set(). It sets the default timezone used by all date/time functions in a script.

date_default_timezone_set('America/Los_Angeles');

Have a look at this page:

http://php.net/manual/en/function.date-default-timezone-set.php

You can find a list of timezones here

http://php.net/manual/en/timezones.php

Alternatively you could change the php.ini file if you have the permissions for it. You could change the option date.timezone to your timezone like this:

date.timezone = "US/Central"

For more information about date.timezone, go to this website:

http://kb.siteground.com/article/How_to_change_the_datetimezone_value_in_PHP.html

0

精彩评论

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