• 用php获取本周,上周,本月,上月,本季度日期的代码


     1 echo date("Ymd",strtotime("now")), "
    ";
     2 echo date("Ymd",strtotime("-1 week Monday")), "
    ";
     3 echo date("Ymd",strtotime("-1 week Sunday")), "
    ";
     4 echo date("Ymd",strtotime("+0 week Monday")), "
    ";
     5 echo date("Ymd",strtotime("+0 week Sunday")), "
    ";
     6  
     7  
     8 //date('n') 第几个月
     9 //date("w") 本周周几
    10 //date("t") 本月天数
    11  
    12 echo '<br>上周:<br>';
    13 echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1-7,date("Y"))),"
    ";
    14 echo date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7-7,date("Y"))),"
    ";
    15 echo '<br>本周:<br>';
    16 echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1,date("Y"))),"
    ";
    17 echo date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7,date("Y"))),"
    ";
    18  
    19 echo '<br>上月:<br>';
    20 echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m")-1,1,date("Y"))),"
    ";
    21 echo date("Y-m-d H:i:s",mktime(23,59,59,date("m") ,0,date("Y"))),"
    ";
    22 echo '<br>本月:<br>';
    23 echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),1,date("Y"))),"
    ";
    24 echo date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("t"),date("Y"))),"
    ";
    25  
    26 $getMonthDays = date("t",mktime(0, 0 , 0,date('n')+(date('n')-1)%3,1,date("Y")));//本季度未最后一月天数
    27 echo '<br>本季度:<br>';
    28 echo date('Y-m-d H:i:s', mktime(0, 0, 0,date('n')-(date('n')-1)%3,1,date('Y'))),"
    ";
    29 echo date('Y-m-d H:i:s', mktime(23,59,59,date('n')+(date('n')-1)%3,$getMonthDays,date('Y'))),"
    ";

    转自:http://www.cnblogs.com/whlives/p/5795458.html

  • 相关阅读:
    第三周:Filter 拦截用户请求部分代码分析
    Story Of Web Background
    XML的前景
    XML的工作原理和过程
    第二周:XML的定义和用途
    企业级应用与互联网应用的区别
    第一周:JavaEE——课程目标
    Java 容器小结
    使用java显示所有操作系统环境变量
    迭代器和Interator的常见用法
  • 原文地址:https://www.cnblogs.com/ygcool/p/6697562.html
Copyright © 2020-2023  润新知