当前位置:Gxlcms > PHP教程 > php获取当天或某个日期是星期几

php获取当天或某个日期是星期几

时间:2021-07-01 10:21:17 帮助过:24人阅读

效果:今天是:星期五今天是:礼拜五2010-12-12是:礼拜日

[PHP]代码

  1. function getWeekName($data,$format = '星期')
  2. {
  3. $week = date( "D ",$data);
  4. switch($week)
  5. {
  6. case "Mon ":
  7. $current = $format."一";
  8. break;
  9. case "Tue ":
  10. $current = $format."二";
  11. break;
  12. case "Wed ":
  13. $current = $format."三";
  14. break;
  15. case "Thu ":
  16. $current = $format."四";
  17. break;
  18. case "Fri ":
  19. $current = $format."五";
  20. break;
  21. case "Sat ":
  22. $current = $format."六";
  23. break;
  24. case "Sun ":
  25. $current = $format."日";
  26. break;
  27. }
  28. return $current;
  29. }
  30. echo '今天是:'.getWeekName(time(),'星期');
  31. echo '
    ';
  32. echo '今天是:'.getWeekName(time(),'礼拜');
  33. echo '
    ';
  34. echo '2010-12-12是:'.getWeekName(strtotime('2010-12-12'),'礼拜');
  35. ?>
php

人气教程排行