Home > Backend Development > PHP Tutorial > PHP method to obtain the current date and the day of the month this Monday is

PHP method to obtain the current date and the day of the month this Monday is

墨辰丷
Release: 2023-03-27 19:36:02
Original
2264 people have browsed it

This article mainly introduces the method of PHP to obtain the current date and the day of the month this Monday is, involving PHP timestamp, date conversion and operation related operation skills. Friends in need can refer to the following

The example in this article describes how PHP obtains the current date and the day of the month this Monday is. Share it with everyone for your reference, the details are as follows:


<?php
  header("content-type:text/html;charset=utf-8");
  date_default_timezone_set(&#39;PRC&#39;);
  function getWeek($unixTime=&#39;&#39;){
    $unixTime=is_numeric($unixTime)?$unixTime:time();
    $weekarray=array(&#39;日&#39;,&#39;一&#39;,&#39;二&#39;,&#39;三&#39;,&#39;四&#39;,&#39;五&#39;,&#39;六&#39;,&#39;七&#39;);
    return "星期".$weekarray[date(&#39;w&#39;,$unixTime)];
  }
  $var=getWeek();
  switch($var){
    case &#39;星期天&#39;:
      $var=time();
      $var2=$var-(84600*6);
      echo "今天是".date("Y-m-d",$var)."号<br/>这个星期一是".date("Y-m-d",$var2)."号";
    break;
    case &#39;星期一&#39;:
      $var=time();
      $var2=$var;
      echo "今天是".date("Y-m-d",$var)."号<br/>这个星期一是".date("Y-m-d",$var2)."号";
    break;
    case &#39;星期二&#39;:
      $var=time();
      $var2=$var-84600;
      echo "今天是".date("Y-m-d",$var)."号<br/>这个星期一是".date("Y-m-d",$var2)."号";
    break;
    case &#39;星期三&#39;:
      $var=time();
      $var2=$var-(84600*2);
      echo "今天是".date("Y-m-d",$var)."号<br/>这个星期一是".date("Y-m-d",$var2)."号";
    break;
    case &#39;星期四&#39;:
      $var=time();
      $var2=$var-(84600*3);
      echo "今天是".date("Y-m-d",$var)."号<br/>这个星期一是".date("Y-m-d",$var2)."号";
    break;
    case &#39;星期五&#39;:
      $var=time();
      $var2=$var-(84600*4);
      echo "今天是".date("Y-m-d",$var)."号<br/>这个星期一是".date("Y-m-d",$var2)."号";
    break;
    case &#39;星期六&#39;:
      $var=time();
      $var2=$var-(84600*5);
      echo "今天是".date("Y-m-d",$var)."号<br/>这个星期一是".date("Y-m-d",$var2)."号";
    break;
  }
?>
Copy after login


The running result is:


今天是2017-03-28号
这个星期一是2017-03-27号
Copy after login


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


Related recommendations:

PHP implementation for date, months, days, weeks, hours, minutes, Methods for addition and subtraction of seconds and so on

PHP method for calculating dateinterval days

A brief talk about Bootstrap’s DatePickerDateRange selection


##

The above is the detailed content of PHP method to obtain the current date and the day of the month this Monday is. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template