简体   繁体   中英

Handling timezones in PHP and MySQL?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM