In the PHP code, obtain the current date time and insert it into the database. By default, PHP explains that the displayed time is "linwei governance standard time", which is 8 hours different from our local time, therefore, the time obtained by date ("Y-m-dH: I: s") is 8 hours less than the current time. The time obtained by the gmdate ("Y-m-dH: I: s") function is subtracted from GMT,
In the PHP code, obtain the current date time and insert it into the database. By default, PHP explains that the displayed time is "linwei governance standard time", which is 8 hours different from our local time, therefore, the time obtained by date ("Y-m-d H: I: s") is 8 hours less than the current time. The time obtained by the gmdate ("Y-m-d H: I: s") function is subtracted from GMT,
Zookeeper
Get the current date and time in the PHP code before inserting the database
By default, PHP interprets the display time as "Greenwich Mean Time", which is 8 hours different from our local time.
So the time obtained by date ("Y-m-d H: I: s") is 8 hours less than the current time.
The gmdate ("Y-m-d H: I: s") function obtains the local time after addition or subtraction with GMT.
In PHP. ini, the date. timezone option is used to set the time zone. However, the time zone is disabled by default and cannot be set in some PHP versions.
Normal implementation.
A better implementation method is to manually correct the time difference as follows:
$timeoffset = 8;echo gmdate("Y-m-d H:i:s", mktime() + $timeoffset * 3600) . "
";echo gmdate("Y-m-d H:i:s", time() + $timeoffset * 3600) . "
";echo date("Y-m-d H:i:s", mktime() + $timeoffset * 3600) . "
";echo date("Y-m-d H:i:s", time() + $timeoffset * 3600) . "
";
Output Format: 17:41:58
Based on the above knowledge, I quickly inserted data. The Code is as follows:
Public function actionAdd () {$ news_model = new News (); $ news_model-> title = "6th News headlines tested "; $ news_model-> pubdate = date ("Y-m-d H: I: s", time () + 8*3600); $ news_model-> author = "yuanpengfei "; if ($ news_model-> save () {echo "success save" ;}else {echo "failed save ";}}