zoukankan      html  css  js  c++  java
  • 输入第几周获取在该年的日期

    方法一

    function GetWeekDate($week){
        date_default_timezone_set('PRC');
        $year = 2016;//哪年
        $week = $week;//第几周
        $day = 1;//星期几

        $last_year = strtotime(($year-1).'-12-31');
        $last_date_lase_year_in_week = date('N',$last_year);
        $days = ($week - 1) * 7 + $day - $last_date_lase_year_in_week;
        $the_day = strtotime("+$days days",$last_year);
        echo date('Y-m-d',$the_day);
    }

    方法二

    function get_week($year) {
        $year_start = $year . "-01-01";
        $year_end = $year . "-12-31";
        $startday = strtotime($year_start);
        if (intval(date('N', $startday)) != '1') {
            $startday = strtotime("next monday", strtotime($year_start)); //获取年第一周的日期
        }
        $year_mondy = date("Y-m-d", $startday); //获取年第一周的日期

        $endday = strtotime($year_end);
        if (intval(date('W', $endday)) == '7') {
            $endday = strtotime("last sunday", strtotime($year_end));
        }

        $num = intval(date('W', $endday));
        for ($i = 1; $i <= $num; $i++) {
            $j = $i -1;
            $start_date = date("Y-m-d", strtotime("$year_mondy $j week "));

            $end_day = date("Y-m-d", strtotime("$start_date +6 day"));

            $week_array[$i] = array (
            str_replace("-", ".", $start_date ), str_replace("-", ".", $end_day));
        }
        echo '<pre>';
        print_r($week_array);
    }

  • 相关阅读:
    一道面试题引发的对JavaScript类型转换的思考
    微信后台开发第一步:nodeJS+express接入微信后台详细教程
    class命名
    了解真实的『REM』手机屏幕适配
    js刷新框架子页面的七种方法代码
    移动前端开发之viewport的深入理解
    移动web点5像素的秘密
    refactor window_x64微信小程序环境搭建
    JSON API免费接口
    webpack
  • 原文地址:https://www.cnblogs.com/maowenqiang/p/5333490.html
Copyright © 2011-2022 走看看