How does phpstrtotime obtain the last Monday time? -1monday error

Source: Internet
Author: User
-The 1 Monday output is the time of this Monday, which is very strange.-1 Monday output is the time of this Monday, which is very strange.

Reply content:

-1 the Monday output is the Monday time, which is very strange.

Because foreigners think that "this Monday" is next Monday and "last Monday" is this Monday
Simply "-2 Monday", or "Monday last week"

Date ('Y-m-D', strtotime ('-'. (6 + date ('w'). 'days '));

-7 days

last week

It usually takes two steps to obtain any day of the last week and then Monday, just as finding the first day of the next month at the end of the month and then-1 day.

Write a general method.

function last_monday($timestamp=0,$is_return_timestamp=true){     static $cache ;     $id = $timestamp.$is_return_timestamp;     if(!isset($cache[$id])){         if(!$timestamp) $timestamp = time();         $thismonday = this_monday($timestamp) - /*7*86400*/604800;         if($is_return_timestamp){             $cache[$id] = $thismonday;         }else{             $cache[$id] = date('Y-m-d',$thismonday);         }     }     return $cache[$id]; }

Date ('w') gets the current day of the week, because Monday to Saturday is 1-6, and Sunday is 0. When the value is 0, last Monday is 13 days ago. The rest are date ('w') + 6 days ago.

$days = date('w')==0?13:date('w')+6;echo date('Y-m-d',time()-$days*86400);

Here we see the document link description

Echo "last Monday:". date ("Y-m-d", strtotime ("last Monday "))."
";

$ Time = strtotime ("-7 day ");

$ Timetest = date ("Y-m-d h: I: sa", $ time );

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.