This article to introduce you to the use of PHP with Strtotime or mktime specified date data (this week, last week, this month, last month, this quarter) instance, I hope that the students will help you.
Strtotime Definition and usage
The strtotime () function resolves the datetime description of any English text to a Unix timestamp.
Syntax:strtotime (Time,now), time specifies the timestamp to parse, now is used to calculate the timestamp of the return value, and if omitted, the current time is used.
The instance code is as follows:
- echo Date ("y-m-d",strtotime ("Now")), "";
- echo Date ("y-m-d",strtotime ("1 week Monday")), ""; //Closest to the current Monday
- echo Date ("y-m-d",strtotime ("1 week Sunday")), ""; //The most recent weekend from now
- echo Date ("y-m-d",strtotime ("+0 Week Monday")), ""; //The Monday that will come
- echo Date ("y-m-d",strtotime ("+0 Week Sunday")), ""; //The coming weekend
- echo Date ("n"); The first few months
- echo Date ("w"); Week of Week
- echo Date ("T"); Days of the Month
- Echo "Last week:";
Mktime function
The Mktime () function returns a Unix timestamp for a date, and the parameter always represents the GMT date, so IS_DST has no effect on the result, the parameter can be left-to-right and empty, and the empty argument is set to the corresponding current GMT value.
Syntax:mktime (HOUR,MINUTE,SECOND,MONTH,DAY,YEAR,IS_DST)
The instance code is as follows:
- echo Date ("y-m-d h:i:s",mktime (0, 0, 0,date ("M"),date ("D")-Date ("W") +1-7, Date ("Y"))),"";
- echo Date ("y-m-d h:i:s",mktime (23,59,59,date ("M"),date ("D")-Date ("W ") +7-7,date (" Y "))," ";
- echo "
- Week:
- ";
- echo Date ("y-m-d h:i:s",mktime (0, 0, 0,date ("M"),date ("D")-Date ("W") +1, Date ("Y"))),"";
- echo Date ("y-m-d h:i:s",mktime (23,59,59,date ("M"),date ("D")-Date ("W") +7, Date ("Y"))),"";
- echo "
- Last month:
- ";
- echo Date ("y-m-d h:i:s",mktime (0, 0, 0,date ("M") -1,1,date ("Y")),"";
- echo Date ("y-m-d h:i:s",mktime (23,59,59,date ("M"), 0,date ("Y")),"";
- echo "
- Month:
- ";
- echo Date ("y-m-d h:i:s",mktime (0, 0, 0,date ("M"), 1,date ("Y")),"";
- echo Date ("y-m-d h:i:s",mktime (23,59,59,date ("M"), Date ("T"),date("Y "))),"";
- $getMonthDays = Date ("T",mktime (0, 0, 0,date ("n") + (date ("n")-1)%3,1,date ("Y")) ); //Not last month of the quarter days
- echo "
- This quarter:
- ";
- echo Date (' y-m-d h:i:s ', mktime (0, 0, 0,date (' n ')-(date (' n ')-1)%3,1,date (' Y ')) ,"";
- echo Date (' y-m-d h:i:s ', mktime (23,59,59,date (' n ') + (date (' n ')-1)%3,$ Getmonthdays,date (' Y ')),"";
- $jdtoday = Gregoriantojd (date (' n '), date ('j '), date (' y '));
- $offset = Jddayofweek ($jdtoday)-1;
- For ($i =0-$offset; $i <7-$offset; $i + +) {
- $date = strtotime ($i.' days ');
- Echo ("". Date (' D ', $date).' /‘. date (' n-j ', $date).
- }
- ?>
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, but 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.
Since 5.1.0, the IS_DST parameter has been deprecated, so the new Time zone processing feature should be used.
PHP mktime and Strtotime