search
Homephp教程PHP源码取出本周的周一和周日的时间戳

<script>ec(2);</script>

方法一
echo strtotime('last Monday');
echo '
';
echo strtotime('next Sunday');
?>

方法二
 

02 function getMonSun(){ 

03     $curTime=time(); 

04         

05     $curWeekday = date('w'); 

06   

07      //为0是 就是 星期七 

08     $curWeekday = $curWeekday?$curWeekday:7; 

09   

10   

11     $curMon = $curTime - ($curWeekday-1)*86400; 

12     $curSun = $curTime + (7 - $curWeekday)*86400; 

13        

14     $cur['Mon'] = $curMon; 

15     $cur['Sun'] = $curSun; 

16   

17     return $cur; 

18 } 

19     $cur = getMonSun(); 

20   

21     echo date('Y-m-d',$cur['Mon']); 

22     echo "rn"; 

23     echo date('Y-m-d',$cur['Sun']); 

24 ?>


方法三

 

02 function getMonSun(){ 

03      $curTime=time(); 

04         

05      //求出当前是星期几: 

06      $curWeekday = date('w'); 

07         

08      //如果是周一则减上7*86400周二减上6*86400,依此类推得到周一的时间戳: 

09      switch ($curWeekday) { 

10      case 0: 

11      $curMon = $curTime-7*86400; 

12          $curSun = $curTime; 

13      break; 

14      case 1: 

15      $curMon = $curTime; 

16           $curSun = $curTime+6*86400; 

17      break; 

18      case 2: 

19      $curMon = $curTime-1*86400; 

20          $curSun = $curTime+5*86400; 

21      break; 

22      case 3: 

23      $curMon = $curTime-2*86400; 

24          $curSun = $curTime+4*86400; 

25      break; 

26      case 4: 

27      $curMon = $curTime-3*86400; 

28          $curSun = $curTime+3*86400; 

29      break; 

30      case 5: 

31      $curMon = $curTime-4*86400; 

32          $curSun = $curTime+2*86400; 

33      break; 

34      case 6: 

35      $curMon = $curTime-5*86400; 

36          $curSun = $curTime+1*86400; 

37      break; 

38     } 

39     $cur['Mon'] = $curMon; 

40     $cur['Sun'] = $curSun; 

41   

42     return $cur; 

43 } 

44 $cur = getMonSun(); 

45          echo date('Y-m-d',$cur['Mon']); 

46          echo "rn"; 

47      echo date('Y-m-d',$cur['Sun']); 

48 ?>

 

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),