php实现星期X转换时间戳的函数实例

  1. <? 
  2. function getTimeFromWeek($dayNum){ 
  3.     //$dayNum:0-6 
  4.     $curDayNum=date("w"); 
  5.     if($dayNum>$curDayNum$timeFlag="last "
  6.     elseif($dayNum==$curDayNum$timeFlag=""
  7.     //如果要本周星期X未到时用本周的星期X else $timeFlag="next"; 
  8.     else $timeFlag="last ";//本周星期X未到时用上周的星期X(让数据不为空) 
  9.     $arryWeekDay = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); 
  10.     $timeStamp=strtotime("$timeFlag"."$arryWeekDay[$dayNum]"); 
  11.     return $timeStamp
  12.         
  13.   
  14. echo date("Y-m-d l",getTimeFromWeek(0));echo "<br>"
  15. echo date("Y-m-d l",getTimeFromWeek(1));echo "<br>"
  16. echo date("Y-m-d l",getTimeFromWeek(2));echo "<br>"
  17. echo date("Y-m-d l",getTimeFromWeek(3));echo "<br>"
  18. echo date("Y-m-d l",getTimeFromWeek(4));echo "<br>"
  19. echo date("Y-m-d l",getTimeFromWeek(5));echo "<br>"
  20. echo date("Y-m-d l",getTimeFromWeek(6));echo "<br>"

 

转载请注明:代码家园 » php实现星期X转换时间戳的函数实例

评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)