Home  >  Article  >  Backend Development  >  PHP date and time application fifteen: print the current date in three formats

PHP date and time application fifteen: print the current date in three formats

藏色散人
藏色散人Original
2021-08-27 09:25:073000browse

In the previous article "PHP Date and Time Application Fourteen: Convert Numbers to Month Names", I introduced you to the method of converting numbers to month names in PHP. Friends in need can learn Find out~

▎Related recommendations: " PHP date and time application summary (continuously updated~)"

Then the theme content of this article is As the title suggests, it teaches you how to print the current date in three formats.

First of all, I want to explain that the content of this article is mainly intended for novices who are just getting started, because it is a very basic and simple knowledge point, which is guaranteed to be understood and mastered by novices at a glance!

In PHP we can use the built-in date() function to obtain the current date information.

Let’s go directly to the code to see how to print the current date in three formats:

The PHP code is as follows:

";
echo date("y.m.d") . "
"; echo date("d-m-y")."
";

Run The results are as follows:

PHP date and time application fifteen: print the current date in three formats

2021/08/27
21.08.27
27-08-21

You can see that the current date is August 27, 2021, so you can use these three formats in development according to your needs.

Needless to say, the role of the PHP date() function is to format the date or time, that is, to format the timestamp into a more readable date and time.

→Note: A timestamp is a sequence of characters that represents the date and event when a specific event occurred.

What you need to master here are some characters commonly used in dates:

The first one is the character d, which represents a certain day in the month; the character m represents the month; the characters Y represent the year; and the character 1 represents the day of the week.

Then if you want to print different formats, you can use other characters, such as "/", "." or "-". By inserting characters, you can add other formats.

Finally, I would like to recommend the latest and most comprehensive "PHP Video Tutorial"~ Come and learn!

The above is the detailed content of PHP date and time application fifteen: print the current date in three formats. 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