Home Backend Development PHP Tutorial PHP date() and time() obtain time that is inconsistent with local time_PHP Tutorial

PHP date() and time() obtain time that is inconsistent with local time_PHP Tutorial

Jul 13, 2016 pm 05:14 PM
date php time and introduce article time local Obtain

This article introduces the solution to the inconsistency between the time obtained by PHP date() and time() and the local time. If necessary, you can refer to the solution

Add it in the program

Use

in the header of the page
The code is as follows
 代码如下 复制代码

date_default_timezone_set()设置我的默认时区为北京时间
date_default_timezone_set('PRC');
echo date('Y-m-d H:i:s');

第一种解决方法:

Copy code

 代码如下 复制代码

date_default_timezone_set('PRC'); //设置本地时区

date_default_timezone_set() sets my default time zone to Beijing time

date_default_timezone_set('PRC');

echo date('Y-m-d H:i:s');

First solution:





Set the default time zone in the program.

The code is as follows Copy code
date_default_timezone_set('PRC'); //Set the local time zone

Second solution: Modify php.ini and change the "date.timezone" item to "date.timezone = PRC" 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 (Macau, Hong Kong, Taipei in order) And Singapore: Asia/Singapore Other available values ​​are: Etc/GMT-8, Singapore, Hongkong, PRC Note: PRC is the People’s Republic of China
http://www.bkjia.com/PHPjc/628944.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/628944.htmlTechArticleThis article introduces the solution to the inconsistency between the time obtained by PHP date() and time() and the local time, if necessary You can refer to the reference solution and add it to the program. Use the code in the header of the page and copy it as follows...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

How To Set Up Visual Studio Code (VS Code) for PHP Development

See all articles