zoukankan      html  css  js  c++  java
  • 获得自然日周月时间

    1.以下函数都可以直接使用。
    function getReportDates($periods){
    $dates = array();
    //当前时间周期的起止时间
    $end = getWeekendByDate($periods);
    $start = date("Y-m-d",strtotime("-".($periods-1). "day",strtotime($end)));
    //获取日期($times个周期)
    $dates['start'] = $start." 00:00:00";
    $dates['end'] = $end." 23:59:59";
    return $dates;
    }

    /**
    * 获取自然 天,周,月
    * @param date:今天的日期
    * @return array:开始时间和结束时间.
    */
    function getWeekendByDate($periods){ //$periods是要的天数 1 7 30

    $st = array(1=>'day',7=>'week',30=>'month');

    if(array_key_exists($periods,$st)){
            $type = $st[$periods];
    }else{
    $type = '';
    }

    switch($type){
    case 'week':
    $day = date('N', time()); //当前日期是星期几
    if($day<2){
    return date("Y-m-d", time() - 86400 * ($day+7));
    }else {//得到上一周的周末日期。
    return date("Y-m-d", time() - 86400 * $day);
    }
    case 'day':
    return date("Y-m-d", time() - 86400 * 2); // 返回前天的日期
    case 'month':
    if((int)date("d",time())<2){
    return date("Y-m-d",strtotime(date("Y-m-0",strtotime("-1 month",strtotime(date("Y-m",time()))))));
    }else{
    return date("Y-m-d",strtotime(date("Y-m-0",time())));
    }
    default:
    return date("Y-m-d",strtotime("-1 day")); //每天的前一天
    }
    }
  • 相关阅读:
    Linux显示2015年日历表
    Linux显示系统日期
    Dialogs 对话框
    grid 属性
    VS2010 fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏 嵌入清单
    Perl Tk grid 布局
    Perl Tk pack布局示例
    Perl Tk grid布局管理器
    Perl DBI模块
    输入文本框模型
  • 原文地址:https://www.cnblogs.com/kobigood/p/4148315.html
Copyright © 2011-2022 走看看