Home>Article>Backend Development> How to use data function in php

How to use data function in php

清浅
清浅 Original
2019-01-11 17:37:15 7591browse

In php, you can format the date and time by setting the parameters in the data function to obtain the time and date

How to use data function in php

[Recommended course:PHP Tutorial

You can use the date() function to compare dates in PHP formatted with time. The first parameter in the data function specifies how to format the date and time. It uses letters to represent date and time

The syntax of the data function:

date(format,timestamp)

where format represents the format of the time, and timestamp represents the specified time, by default The following refers to the current time and date

Here are some commonly used date characters

d: represents a certain day of the month (01-31)

m: Indicates the month (01-12)

Y: Indicates the year (four digits)

1: Indicates a day of the week

h : 12-hour hour format with leading zero

i : Minutes with leading zero

s : Seconds with leading zero (00 -59)

a : Lowercase noon and noon (am or pm)

Other characters, such as "/", "." or "-" can also be inserted into the characters to add other formats.

Specific usage of the data() function:

Get the current date and time

Rendering:

How to use data function in php

Note: When using PHP5.3 or above, if the php.ini file is not configured correctly, an error in the PHP date function will occur. So we need to add a line of date_default_timezone_set('PRC'); code in front of php. The purpose is to make it enter the correct date time.

Get the number of days in a certain time

Rendering:

How to use data function in php

Summary: The above is about the data How to use it, I hope it will be helpful to everyone.

The above is the detailed content of How to use data function 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