search
HomeBackend DevelopmentPHP ProblemHow to get the current date in php

How to get the current date in php

Sep 24, 2019 pm 01:04 PM
phpcurrent dateObtain

How to get the current date in php

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.

How to get the current date in php

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.

How to get the current date in php

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(&#39;Y-m-d&#39;);
>

Check the running effect in the browser and you can see that the server time is displayed successfully!

How to get the current date in php

#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(&#39;Y&#39;).&#39;年&#39;.date(&#39;m&#39;).&#39;月&#39;.date(&#39;d&#39;).&#39;日&#39;;
>

How to get the current date in php

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!

Statement
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 AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

DVWA

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

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool