Home  >  Article  >  Backend Development  >  How to get the date of this Monday in php

How to get the date of this Monday in php

墨辰丷
墨辰丷Original
2018-06-11 14:49:023787browse

This article mainly introduces the method of PHP to obtain the specific date of Monday this week. It involves PHP's date operation skills. It is of great practical value. Interested friends can integrate this code snippet into their own date class. For the convenience of future calls, friends in need can refer to

. The example in this article describes how to get the specific date of Monday this week in php. The details are as follows:

private function mondayTime($timestamp=0,$is_return_timestamp=true){
  static $cache ;
  $id = $timestamp.$is_return_timestamp;
  if(!isset($cache[$id])){
   if(!$timestamp) $timestamp = time();
   $monday_date = date('Y-m-d',$timestamp-86400*date('w',$timestamp)+(date('w',$timestamp)>0?86400:-/*6*86400*/518400));
   if($is_return_timestamp){
    $cache[$id] = strtotime($monday_date);
   }else{
    $cache[$id] = $monday_date;
   }
  }
  return $cache[$id];
}
echo $this->mondayTime(time() + 24*3600*2,false);
exit;

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

Related recommendations:

PHP implements clearing images that have not been accessed within a fixed date

php string and Methods of process control

16 common basic PHP functions

The above is the detailed content of How to get the date of this Monday in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn