In PHP we have to add to the time and date we can use two functions, mktime and strtotime functions, let me give you students to introduce their use methods.
Mktime function
The Mktime () function returns a Unix timestamp for a date.
The parameter always represents the GMT date, so IS_DST has no effect on the result.
Parameters can be left-to-right and empty, and empty parameters will be set to the corresponding current GMT value.
Parameter description
Hour is optional. Specified hours.
Minute is optional. Specify minutes.
Second is optional. Specify seconds.
Month is optional. Specifies the number of months to be represented.
Day is optional. Prescribed days.
Year is optional. Prescribed year. On some systems, the legal value is between 1901-2038. However, there is no such limit in PHP 5.
IS_DST is optional. If the time is in daylight saving time (DST), set to 1, otherwise set to 0 and if unknown, set to-1.
Example
The Mktime () function is useful for date arithmetic and validation. It can automatically correct out-of-bounds input:
The code is as follows |
Copy Code |
Echo (Date ("M-d-y", Mktime (0,0,0,12,36,2001))); Echo (Date ("M-d-y", Mktime (0,0,0,14,1,2001))); Echo (Date ("M-d-y", Mktime (0,0,0,1,1,2001))); Echo (Date ("M-d-y", Mktime (0,0,0,1,1,99))); ?> Output: jan-05-2002 feb-01-2002 jan-01-2001 jan-01-1999 Strtotime (Time,now)
|
In a small project to use the comparison of the chain data, the data span is one weeks, to achieve the positioning of the time so write two functions, welcome to shoot bricks.
Date calculated for Monday:
The code is as follows |
Copy Code |
function Getthemonday ($date) { if (date (' N ', Strtotime ($date)) = = 1) { Return date (' y-m-d ', strtotime (' Monday ', Strtotime ($date))); } else { Return date (' y-m-d ', Strtotime (' Last Monday ', Strtotime ($date))); } } |
Date calculated for Sunday:
The code is as follows |
Copy Code |
function Getthesunday ($date) { Return date (' y-m-d ', strtotime (' Sunday ', Strtotime ($date))); } |
http://www.bkjia.com/PHPjc/445608.html www.bkjia.com true http://www.bkjia.com/PHPjc/445608.html techarticle in PHP we have to add to the time and date we can use two functions, mktime and strtotime functions, let me give you students to introduce their use methods. Mktime function mktime () Letter ...