PHP Specifies date data with Strtotime or mktime (this week, last week, month, month, quarter)

Source: Internet
Author: User
Tags current time echo date

Strtotime Definitions and usage

The strtotime () function resolves the date-time description of any English text to a Unix timestamp.

Grammar

Strtotime (time,now) parameter description
Time to specify the string to parse.
Now is the time stamp used to calculate the return value. If this argument is omitted, the current time is used.

Cases

The code is as follows Copy Code

echo Date ("Y-m-d", Strtotime ("Now")), "<br/>";
echo Date ("Y-m-d", Strtotime ("-1 week Monday"), "<br/>"; From the recent Monday
echo Date ("Y-m-d", Strtotime ("-1 week Sunday"), "<br/>"; It's the latest weekend.
echo Date ("Y-m-d", Strtotime ("+0 Week Monday"), "<br/>"; The coming Monday
echo Date ("Y-m-d", Strtotime ("+0 Week Sunday"), "<br/>"; The coming weekend
echo Date ("n");//months
Echo Date ("W")//week of week
echo Date ("T");//Days of the Month
echo "<br/> last week: <br/>";


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.

The parameters can be left-to-right, and the empty arguments will be set to the appropriate current GMT value.

Grammar

Mktime (HOUR,MINUTE,SECOND,MONTH,DAY,YEAR,IS_DST)

Cases

The code is as follows Copy Code
echo Date ("Y-m-d h:i:s", mktime (0, 0, 0,date ("M"), Date ("D")-date ("W") +1-7,date ("Y")), "<br/>";
echo Date ("Y-m-d h:i:s", Mktime (23,59,59,date ("M"), Date ("D")-date ("W") +7-7,date ("Y")), "<br/>";
echo "<br> this week:<br>";
echo Date ("Y-m-d h:i:s", mktime (0, 0, 0,date ("M"), Date ("D")-date ("W") +1,date ("Y")), "<br/>";
echo Date ("Y-m-d h:i:s", Mktime (23,59,59,date ("M"), Date ("D")-date ("W") +7,date ("Y")), "<br/>";
echo "<br> last month:<br>";
echo Date ("Y-m-d h:i:s", mktime (0, 0, 0,date ("M") -1,1,date ("Y")), "<br/>";
echo Date ("Y-m-d h:i:s", Mktime (23,59,59,date ("M"), 0,date ("Y")), "<br/>";
echo "<br> this month:<br>";
echo Date ("Y-m-d h:i:s", mktime (0, 0, 0,date ("M"), 1,date ("Y")), "<br/>";
echo Date ("Y-m-d h:i:s", Mktime (23,59,59,date ("M"), Date ("T"), Date ("Y")), "<br/>";
$getMonthDays = Date ("T", mktime (0, 0, 0,date ("n") + (date ("n")-1)%3,1,date ("Y"));
echo "<br> this quarter:<br>";
echo Date (' y-m-d h:i:s ', mktime (0, 0, 0,date (' n ')-(date (' n ')-1)%3,1,date (' Y ')), "<br/>";
echo Date (' y-m-d h:i:s ', Mktime (23,59,59,date (' n ') + (date (' n ')-1)%3, $getMonthDays, date (' Y ')), "<br/>";
$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 (' <th> '. Date (' D ', $date). " /'. Date (' N-j ', $date). ' </th> ');
}
?>

Parameters Description
Hour Optional. Set hours.
Minute Optional. Specify minutes.
Second Optional. Specified seconds.
Month Optional. A month that is specified in numbers.
Day Optional. Stipulated day.
Year Optional. Set year. On some systems, the legal value is between 1901-2038. However, there is no such limit in PHP 5.
Is_dst

Optional. If time is in daylight saving time (DST), set to 1, otherwise set to 0, if unknown, set to-1.

Since 5.1.0, IS_DST parameters have been discarded. Therefore, you should use the new time zone processing attributes.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.