zoukankan      html  css  js  c++  java
  • php 计算指定年份的周总数与及第几周的开始日期和结束日期(从周一开始)

    /**
    * 获取某年第几周的开始日期和结束日期
    * @param int $year
    * @param int $week 第几周;
    */
    public function weekday($year,$week=1){
    $year_start = mktime(0,0,0,1,1,$year);
    $year_end = mktime(0,0,0,12,31,$year);

    // 判断第一天是否为第一周的开始
    if (intval(date('W',$year_start))===1){
    $lastday=date("Y-m-d",strtotime(date('Y-m-d',$year_start)." Sunday"));
    $start=strtotime(date("Y-m-d",strtotime($lastday."-6 days")));
    //$start = $year_start;//把第一天做为第一周的开始
    }else{
    $start = strtotime('+1 monday',$year_start);//把第一个周一作为开始
    }

    // 第几周的开始时间
    if ($week==1){
    $weekday['start'] = $start;
    }else{
    $weekday['start'] = strtotime($week.' monday',$start);
    }

    // 第几周的结束时间
    $weekday['end'] = strtotime('+1 sunday',$weekday['start']);
    if (date('Y',$weekday['end'])!=$year){
    $weekday['end'] = $year_end;
    }
    return $weekday;
    }

    /**
    * 计算一年有多少周,每周从星期一开始,
    * 如果最后一天在周四后(包括周四)算完整的一周,否则不计入当年的最后一周
    * 如果第一天在周四前(包括周四)算完整的一周,否则不计入当年的第一周
    * @param int $year
    * return int
    */
    public function week($year){
    $year_start = mktime(0,0,0,1,1,$year+1);
    $year_end = mktime(0,0,0,12,31,$year);

    if (date('oW',$year_end)==date('oW',$year_start)){
    return date('W',strtotime('last week',$year_end));
    }else{
    return date('W',$year_end);
    }
    }

  • 相关阅读:
    Ubuntu安装teamviewer(附带解决dpkg占用的代码)
    使用print时出错 SyntaxError: Missing parentheses in call to 'print' Did you mean print("Usage....
    非root用户(普通用户)安装CMake
    Permanently added the RSA host key for IP address '13.229.188.59' Permission denied (publickey)fatal
    django6-admin
    django6-信号
    django6-缓存
    django6 -中间件
    天津去哪玩
    django--->form表单
  • 原文地址:https://www.cnblogs.com/lin-er/p/11295653.html
Copyright © 2011-2022 走看看