1. Prerequisites
In PHP website programming, we generally use the date function to obtain the time on the server. But in order to call the date function correctly, you must ensure that the php configuration file php.ini has been configured correctly, otherwise an error will be reported when calling the date function and the time cannot be obtained correctly.
2. Use the Notepad program to open the php configuration file php.ini and look for the "date.timezone = " item. If there is ";" in front of it, remove the previous one. ";", and change the value of this item to: date.timezone = PRC or date.timezone = "Asia/Shanghai". After saving the configuration, you need to restart the server for the modified configuration to take effect.
3. Get the date
After the configuration file is modified, we can call the date function to get the current server time. The relevant code is as follows:
<?php echo "当前系统日期为:".date('Y-m-d'); >
Check the running effect in the browser and you can see that the server time is displayed successfully!
#4. Format and adjust the display format of the obtained date.
The following code can display a date format that is more in line with our Chinese habits:
<?php echo "当前系统日期为:".date('Y').'年'.date('m').'月'.date('d').'日'; >
Recommended tutorial: PHP video tutorial
The above is the detailed content of How to get the current date in php. For more information, please follow other related articles on the PHP Chinese website!

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

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