Home > Backend Development > PHP Problem > How to get the current number in php

How to get the current number in php

藏色散人
Release: 2023-03-05 18:16:02
Original
4492 people have browsed it

In PHP, you can get the current date through the "PHP Date()" function. The syntax of this function is "date(format, timestamp)", where when the "format" parameter is "d", It means getting the day of the month.

How to get the current number in php

Recommended: "PHP Video Tutorial"

To get the current time, you need to use the PHP Date() function.

PHP Date() Format the timestamp into a more readable date and time.

Syntax:

date(format,timestamp)
Copy after login

The parameter format is the display format, and the parameter timestamp is the timestamp, which is optional. The default is time(), that is, if no timestamp is given, the local current is used. time.

format format parameters are briefly introduced here:

Some characters commonly used in dates:

Y - Complete representation of the year (four digits: 2019)

y - represents the year (two digits: 19)

F - represents the month (full text format: January or March)

M - represents the month (3 letters: Jun )

m - indicates the month, with leading 0 (number: 04)

n - indicates the month, without leading 0 (number: 4)

d - indicates the middle of the month The day of the month, with leading 0 (01-31)

j - represents the day of the month, without leading 0 (1-31)

D - represents the day of the week (3 Letter: Wed)

l - represents the day of the week (full English: Wednesday)

w - represents the day of the week (number, 0 represents Sunday)

W - Indicates the number of weeks in the year

z - Indicates the number of days in the year (0-366)

Example:

<?php
    echo "<p>今天是:" . date("Y/m/d") . "</p>";
    echo "<p>今天是:" . date("Y.m.d") . "</p>";
    echo "<p>今天是:" . date("Y-m-d") . "</p>";
    echo "<p>今天是:" . date("l") . "</p>";
?>
Copy after login

Run results:

PHP gets the current time, year, month, date and number of days PHP notes No. 2

If you want the year, month and day in Chinese, you can write like this:

echo "The current time is:" . date("Y year m month d day");

Run result:

Today is: April 24, 2019

The above is the detailed content of How to get the current number in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template