问题描述
限时送ChatGPT账号..在我的网络应用程序中,我让用户从列表中选择他们喜欢的时区(包含 PHP 支持的所有时区).
In my web app, I let the users choose their preferred timezone from a list (that contains all timezones that PHP supports).
假设 $_POST['timezone']
是选择的时区(例如 America/New_York
).我使用以下不会产生错误的代码对其进行设置:
Let's say that $_POST['timezone']
is the chosen timezone (e.g. America/New_York
).
I set it with the following code which produces no errors:
default_date_timezone_set($_POST['timezone']);
但是当我重新加载页面时,它会回到之前的状态(例如 Europe/Moscow
).我是否必须在每个脚本中设置默认时区,或者函数 (default_date_timezone_set
) 是否正常工作?谢谢!
But when I reload the page it goes back to what it was before (e.g. Europe/Moscow
).
Do I have to set the default timezone in every script or isn't the function (default_date_timezone_set
) working properly?
Thanks!
推荐答案
此函数仅更改脚本执行的时区.您可以将时区存储在会话变量中,并在每个页面的顶部设置时区.
This function changes the timezone for the execution of the script only. You could store the timezone in a session variable and set the time zone on top of every page.
这篇关于设置 PHP 的默认时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论