date_default_timezone_set() sets the time zone
##
<?php echo function_exists(date_default_timezone_set)."<br>";//在这他总是返回1,这函数是判断这里面的字符是不是一个定义了的函数名 echo date('Y-m-d H:i:s')."<br>";//默认时区的时间 echo date_default_timezone_set("Etc/GMT")."<br>";//这是格林威治标准时间,得到的时间和默认时区是一样的 echo date('Y-m-d H:i:s')."<br>"; echo date_default_timezone_set("Etc/GMT+8")."<br>";//这里比林威治标准时间慢8小时 echo date('Y-m-d H:i:s')."<br>"; echo date_default_timezone_set("Etc/GMT-8")."<br>";//由上一个不能难想像,我们比那快8小时所以减8 echo date('Y-m-d H:i:s')."<br>"; echo date_default_timezone_set('PRC')."<br>"; //设置中国时区 echo date('Y-m-d H:i:s')."<br>";//中国标准时间 ?> //输出 1 2009-05-15 02:20:42 //默认时区时间 1 2009-05-15 02:20:42 //("Etc/GMT") 格林威治标准时间 1 2009-05-14 18:20:42 //("Etc/GMT+8") 比林威治标准时间慢8小时 1 2009-05-15 10:20:42 //("Etc/GMT-8") 比林威治标准时间快8小时,是我们的北京时间 1 2009-05-15 10:20:42 //('PRC') 中国标准时间
There was a legacy problem before, that is, the time returned by echo date("y-m-d h:i:s", time()) always did not match the actual time. Today I finally found the reason and solution online. Share as follows:
I would like to add that I modified php.ini according to the following tips and could not find the date.timezone line. Is there nothing I can do? Of course not, haha, if not, just add it yourself. Well, you can make enough food and clothing by yourself. I added date.timezone = "PRC" and the problem was solved. I'm happy.
Starting from php5.1.0, the date.timezone option has been added to php.ini. It is turned off by default. The
means that the displayed time (no matter what php command is used) is Greenwich Mean Time.
is exactly 8 hours different from our time (Beijing time). There are the following 3 Method can restore normal time.
1, the simplest way is not to use php5.1 or above version
2, if you must use it, and you cannot modify php.ini, you need to initialize the time statement
Add date_default_timezone_set (XXX);
cp does not have this problem
3, once and for all, only php.ini can be modified. Open php.ini and search for date.timezone. Remove the semicolon in front
= and add XXX after it. Restart the http service (such as apache2 or iis, etc.)
Regarding XXX, the available values in mainland China are: Asia /Chongqing, Asia/Shanghai, Asia/Urumqi (in order Chongqing, Shanghai, Urumqi)
Available in Hong Kong and Taiwan: Asia/Macao, Asia/Hong_Kong, Asia/Taipei (in order Macau, Hong Kong, Taipei)
And Singapore: Asia/Singapore
Foreigners seem to have missed Beijing
Other available values are: Etc/GMT-8, Singapore, Hongkong, PRC
What is PRC? PRC is the People's Republic of China -_-
The above is the detailed content of date_default_timezone_set() method to set time zone in PHP. For more information, please follow other related articles on the PHP Chinese website!

如果您正在寻找根据系统时间戳自动创建文件和文件夹并为其命名的方法,那么您来对地方了。有一种超级简单的方法可以用来完成这项任务。然后,创建的文件夹或文件可用于各种目的,例如存储文件备份、根据日期对文件进行排序等。在本文中,我们将通过一些非常简单的步骤解释如何在Windows11/10中自动创建文件和文件夹,并根据系统的时间戳对其进行命名。使用的方法是批处理脚本,非常简单。希望你喜欢阅读这篇文章。第1节:如何根据系统当前时间戳自动创建文件夹并命名第1步:首先,导航到要在其中创建文件夹的父文件夹,

在使用PHP程序开发时,经常会碰到一些警告或者错误的提示信息。其中,可能出现的一个错误提示就是:PHPWarning:date()expectsparameter2tobelong,stringgiven。这个错误的提示信息意思是:函数date()的第二个参数期望是长整型(long),但是实际传递给它的是字符串(string)。那么,我们

一.介绍java.util包中的Date类表示特定的时间,精确到毫秒。如果要想使用我们的Date类,那么我们必须得引入我们的Date类。Date类直接写入年份是得不到正确的结果的。因为java中Date是从1900年开始算的,所以前面的第一个参数只要填入从1900年后过了多少年就是你想要得到的年份。月需要减1,日可以直接插入。这种方法用的比较少,常用的是第二种方法。这种方法是将一个符合特定格式,比如yyyy-MM-dd,的字符串转化成为Date类型的数据。首先,定义一个Date类型的对象Date

如何使用Date类的getTime()方法获取日期的毫秒表示形式在Java中,Date类是用于表示日期和时间的类。它提供了许多有用的方法来操作和获取日期对象的信息。其中,getTime()方法是Date类中的一个重要方法,它可以返回日期对象的毫秒表示形式。接下来,我们将详细介绍如何使用这个方法来获取日期的毫秒表示形式,并提供相应的代码示例。使用Date类的g

Python中有许多优秀的日历库和日期库供我们使用,这些库可以帮助我们处理日期和日历相关的操作。接下来,我将为大家介绍几个常用的选择,并提供相应的代码示例。datetime库:datetime是Python内置的日期和时间处理模块,提供了许多日期和时间相关的类和方法,可以用于处理日期、时间、时间差等操作。示例代码:importdatetime#获取当

Stringbuild类由于String类的对象内容不可改变,每次拼接都会构建一个新的String对象,既耗时,又浪费内存空间这时需要通过java提供的StringBuild类解决这个问题StringBuilder又称为可变字符序列,它是一个类似于String的字符串缓冲区,可以看作是一个容器,容器中可以装很多字符串可变指的是StringBuilder对象中的内容是可变的构造方法publicStringBuilder():创建一个空的缓冲区publicStringBuilder(Stringsr

配置default gateway的步骤:1、确定路由器的IP地址;2、打开计算机的网络配置界面;3、配置网络连接;4、配置IPv4设置;5、输入IP地址和子网掩码;6、配置默认网关;7、配置DNS服务器;8、保存设置。详细介绍:1、确定路由器的IP地址,默认网关的地址通常是路由器的IP地址,在路由器的背面或用户手册中,可以找到路由器的IP地址;2、打开计算机的网络配置等等。

遇到一个问题,springboot升级成2.0后,从数据库查出来的日期,用Date接收,最后直接返回给前端,在谷歌浏览器中能正常显示成yyyy-MM-ddHH:mm:ss格式。但是在IE浏览器中日期显示的是“乱码”,因为springboot1.x版本的默认将Date字段返回的是时间戳,而谷歌、IE都会自动将时间戳转换成yyyy-MM-ddHH:mm:ss;在springboot2.0后,spring会将Date字段自动给转成UTC字符串了(在没有配置的情况下),所以date需要转换成时间戳还是y


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Chinese version
Chinese version, very easy to use

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.
