欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php日期实例:取得上周,本周,上月,本月,本季度,上季度

程序员文章站 2022-05-07 19:46:02
...

例子,php获取上周,本周,上月,本月,本季度,上季度。

  1. date_default_timezone_set('PRC');
  2. date("Y-m-d H:i:s", strtotime(" +2 year"));
  3. date("Y-m-d H:i:s", strtotime(" +2 month"));
  4. date("Y-m-d H:i:s", strtotime(" +2 week"));
  5. date("Y-m-d H:i:s", strtotime(" +2 day"));
  6. date("Y-m-d H:i:s", strtotime(" +2 hour"));
  7. date("Y-m-d H:i:s", strtotime(" +2 minute"));
  8. date("Y-m-d H:i:s", strtotime(" +2 second"));
  9. echo date("Ymd",strtotime("now")), "\n";
  10. echo date("Ymd",strtotime("-1 week Monday")), "\n";
  11. echo date("Ymd",strtotime("-1 week Sunday")), "\n";
  12. echo date("Ymd",strtotime("+0 week Monday")), "\n";
  13. echo date("Ymd",strtotime("+0 week Sunday")), "\n";
  14. echo "*********第几个月:";
  15. echo date('n');
  16. echo "*********本周周几:";
  17. echo date("w");
  18. echo "*********本月天数:";
  19. echo date("t");
  20. echo "*********";
  21. echo '
    上周:
    ';
  22. echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1-7,date("Y"))),"\n";
  23. echo date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7-7,date("Y"))),"\n";
  24. echo '
    本周:
    ';
  25. echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1,date("Y"))),"\n";
  26. echo date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7,date("Y"))),"\n";
  27. echo '
    上月:
    ';
  28. echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m")-1,1,date("Y"))),"\n";
  29. echo date("Y-m-d H:i:s",mktime(23,59,59,date("m") ,0,date("Y"))),"\n";
  30. echo '
    本月:
    ';
  31. echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),1,date("Y"))),"\n";
  32. echo date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("t"),date("Y"))),"\n";
  33. $season = ceil((date('n'))/3);//当月是第几季度
  34. echo '
    本季度:
    ';
  35. echo date('Y-m-d H:i:s', mktime(0, 0, 0,$season*3-3+1,1,date('Y'))),"\n";
  36. echo date('Y-m-d H:i:s', mktime(23,59,59,$season*3,date('t',mktime(0, 0 , 0,$season*3,1,date("Y"))),date('Y'))),"\n";
  37. $season = ceil((date('n'))/3)-1;//上季度是第几季度
  38. echo '
    上季度:
    ';
  39. echo date('Y-m-d H:i:s', mktime(0, 0, 0,$season*3-3+1,1,date('Y'))),"\n";
  40. echo date('Y-m-d H:i:s', mktime(23,59,59,$season*3,date('t',mktime(0, 0 , 0,$season*3,1,date("Y"))),date('Y'))),"\n";
  41. ?>
复制代码