Home >Backend Development >PHP Problem >How to calculate what day of the year today is in php
Method: 1. Use the "time()" function to obtain the timestamp of the current time; 2. Use the date() function and the z character to format the obtained timestamp into the day of the year, syntax It is "date("z", timestamp)"; 3. Use the echo statement to output the number of days obtained.
The operating environment of this tutorial: windows10 system, PHP7.1 version, DELL G3 computer
The time() function returns the number of seconds since the Unix epoch (January 1 1970 00:00:00 GMT).
The syntax is:
time();
PHP date() function is used to format time/date.
PHP date() function can format the timestamp into a more readable date and time.
The syntax is:
string date ( string $format [, int $timestamp ] )
The first required parameter format of the date() function specifies how to format the date/time.
z represents the day of the year
The example is as follows:
<?php $a=time(); $b=date("z",$a); echo "今天是本年的第".$b."天"; ?>
Output result:
Summary:
1. Obtain the timestamp of the current time through the time() function.
2. Then use the date() function and use the z character to calculate the day of the year that the current time is.
3. Use echo to output the obtained results.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to calculate what day of the year today is in php. For more information, please follow other related articles on the PHP Chinese website!