Home > Backend Development > PHP Tutorial > PHP implements the function of converting week X to timestamp

PHP implements the function of converting week X to timestamp

WBOY
Release: 2016-07-25 09:01:50
Original
933 people have browsed it
To build an animation website, you need to update the list every week and call up the data from Monday to Sunday.
Write a function to implement key functions.
  1. function getTimeFromWeek($dayNum){
  2. //$dayNum:0-6
  3. $curDayNum=date("w");
  4. if($dayNum>$curDayNum) $timeFlag="last " ;
  5. elseif($dayNum==$curDayNum) $timeFlag="";
  6. //If you want to use this week's day X when day X has not arrived this week else $timeFlag="next";
  7. else $timeFlag="last ";//If week X does not arrive this week, use last week's day 'Friday','Saturday');
  8. $timeStamp=strtotime("$timeFlag"."$arryWeekDay[$dayNum]");
  9. return $timeStamp;
  10. }
  11. echo date("Y-m-d l",getTimeFromWeek( 0));echo "
    ";
  12. echo date("Y-m-d l",getTimeFromWeek(1));echo "
    ";
  13. echo date("Y-m-d l",getTimeFromWeek(2)); echo "
    ";
  14. echo date("Y-m-d l",getTimeFromWeek(3));echo "
    ";
  15. echo date("Y-m-d l",getTimeFromWeek(4));echo "< br>";
  16. echo date("Y-m-d l",getTimeFromWeek(5));echo "
    ";
  17. echo date("Y-m-d l",getTimeFromWeek(6));echo "
    ";
Copy code

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