PHP provides a variety of functions for getting time and date. apart from getting the current UNIX timestamp using the time () function and getting the current time using the date function, you can also call the getdate () function to determine the current time. This chapter introduces the "getdate ()" function. PHP provides a variety of functions for getting time and date. apart from getting the current UNIX timestamp using the time () function and getting the current time using the date function, you can also call the getdate () function to determine the current time. This chapter introduces the "getdate ()" function.
Usage of the getdate () function:
The getdate () function is used to obtain information about the specified part of a date. Its syntax is as follows:
getdate(timestamp);
The getdate () function returns the date and time information in the array format. if there is no timestamp parameter, the current time prevails. The joined array elements returned by this function are listed in the following table:
Description of joined array elements returned by the getdate () function
Key name |
Description |
Return value example |
"Seconds" |
Number of seconds |
0To59 |
"Minutes" |
Minute numeric representation |
0To59 |
"Hours" |
Number of hours |
0To23 |
"Mday" |
Number of the day of the month |
1To31 |
"Wday" |
Number of the day of the week |
0(Sunday)6(Saturday) |
"Mon" |
Number of months |
1To12 |
"Year" |
The full year represented by four digits |
For example:1999Or2003 |
"Yday" |
Number of the day of the year |
0To365 |
"Weekday" |
Complete text representation of the day of the week |
SundayToSaturday |
"Month" |
Complete text representation of the month |
January>ToDecember |
0 |
The number of seconds since the beginning of the Unix era, similar to the return value of time () and the value used for date. |
System-related. the typical value is from-2147483648To2147483647. |
Getdate () functionInstance
Instance 1
This example uses the getdate () function without parameters. the code is as follows:
The running result is as follows:
Instance 2
Use the getdate () function to obtain the current date information of the system and output the return value of this function. the instance code is as follows:
"; Echo" today is the $ arr [yday] th of year ";?>
The running result is as follows:
The above is a simple application of the getdate () function.
We all know that 12 months a year, 7 days a week ......, but the computer does not know, so we also need to check whether the date is valid. in the next section, we will introduce the use of PHP functions to check the validity of the date.
The above is the detailed description of the php getdate () function to obtain the date information instance. For more information, see other related articles in the first PHP community!