设置 PHP 的默认时区

编程入门 行业动态 更新时间:2024-10-26 16:33:43
本文介绍了设置 PHP 的默认时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-04-30 12:55:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1394549.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时区   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!