In PHP, there are several functions to get time and date, in addition to the time () function to get the current UNIX timestamp and using the DATE function to get the current time, you can also call the GETDATE () function to determine the current time, this chapter will introduce you to the "getdate ()" function.
Use of the GETDATE () function:
The GETDATE () function is the information that gets the specified part of the date specified, and its syntax is as follows:
GETDATE (timestamp);
The GETDATE () function returns the date and time information in the form of an array, if there is no parameter timestamp, whichever is the current time. The associated array element returned by the function is the following table:
The GETDATE () function returns an associative array element description
Key Name |
Description |
example of return value |
"Seconds" |
The number of seconds is expressed |
0 to |
"Minutes" |
The number of minutes indicates |
0 to |
"Hours" |
The number of hours indicates |
0 to |
"Mday" |
The number of days in the month indicates |
1 to |
"Wday" |
The number of days of the week indicates |
0(for Sunday) to 6(= Saturday) |
"Mon" |
Numeric representation of the month |
1 to |
"Year" |
Full Year 4-digit representation |
Example:1999 or 2003 |
"Yday" |
The number of days in a year indicates |
0 to 365 |
"Weekday" |
Full text representation of the day of the week |
Sunday to Saturday |
"Month" |
Full text representation of the month |
january> to December |
0 |
The number of seconds since the Unix era began, similar to the return value of Time () and the value used for date () . |
System-dependent, typical values are from -2147483648 to 2147483647. |
getdate () function Example
Instance One
This example uses the GETDATE () function without parameters and the code is as follows:
<?php$time=getdate ();p rint_r ($time);? >
Running results such as:
The GETDATE () function returns date and time information as an array, so Print_r () is used to print.
Example Two
Use the GETDATE () function to get the current date information for the system and output the return value of the function, as shown in the example code:
<?phpheader ("Content-type:text/html;charset=utf-8"); Set the encoding $arr=getdate (); Echo $arr [year]. " -". $arr [Mon]." -". $arr [Mday]." "Echo $arr [hours].": "$arr [minutes].": ". $arr [seconds]." ". $arr [weekday]." <br/> "; echo" Today is the $arr [yday]th of year];? >
Running results such as:
Above is the simple application of our getdate () function.
We all know that one year 12 months, one weeks 7 days ..., but the computer is not known, so we have to check that the date is not valid, the next section, we will introduce the use of PHP functions to verify the validity of the date.