Heim  >  Artikel  >  Backend-Entwicklung  >  PHP根据当天的年月日获取当前周的周日的年月日

PHP根据当天的年月日获取当前周的周日的年月日

WBOY
WBOYOriginal
2016-07-25 08:42:32973Durchsuche
  1. //获取年月日对应的最近的周天的截止日期 可能会 跨年 跨月 跨周
  2. function GetClearWeek() {
  3. $year_month_day_over = array();
  4. $year = date('Y'); //四位 的年份
  5. $month = date('n'); //1 到 12
  6. $day_of_month = date('j');//1-31 月份中的第几天
  7. $day_of_week = date('N'); //1-7 周中的第几天
  8. $day_of_year = date('z')+1; // 1-366 年的第几天
  9. $days_of_month = date('t'); //当前月份 月份应有的天数
  10. $day_should_over = $day_of_month - $day_of_week + 7;
  11. if($day_should_over > $days_of_month) {
  12. $month_over = $month + 1;
  13. if($month_over > 12) {
  14. $year_month_day_over = array(
  15. 'year_over' => $year + 1,'month_over' => 1,'day_over' => $day_should_over - $days_of_month,
  16. );
  17. } else {
  18. $year_month_day_over = array(
  19. 'year_over' => $year ,'month_over' => $month + 1,'day_over' => $day_should_over - $days_of_month,
  20. );
  21. }
  22. } else {
  23. $year_month_day_over = array(
  24. 'year_over' => $year ,'month_over' => $month,'day_over' => $day_should_over,
  25. );
  26. }
  27. return $year_month_day_over;
  28. }
复制代码

PHP


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn