zoukankan      html  css  js  c++  java
  • PHP日期处理

    // 前n天 
    echo date("Y-m-d", strtotime('-n day'));
    
    // 后n天
    echo date("Y-m-d", strtotime('+n day'));
    
    //本周一
    echo date('Y-m-d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600));
    
    //本周日
    echo date('Y-m-d', (time() + (7 - (date('w') == 0 ? 7 : date('w'))) * 24 * 3600));
    
    //上 n 周一
    echo date('Y-m-d', strtotime('-n monday', time()));
    
    //上 n 周日
    echo date('Y-m-d', strtotime('-n sunday', time()));
    
    //上n周同天
    echo date('Y-m-d', strtotime("-7*n day"));
    
    //本月一号
    echo date('Y-m-01');
    
    //本月最后一天
    echo date("Y-m-d", strtotime(date("Y-m-01",strtotime("+1 month")))-86400);
    echo date('Y-m-d', strtotime(date('Y-m', time()) . '-' . date('t', time()) . ' 00:00:00'));30
    
    //上月一号
    echo date('Y-m-01', strtotime('-1 month'));
    
    //上月最后一天
    echo date("Y-m-d",strtotime(date("Y-m-01")) - 86400);
    echo date('Y-m-d', strtotime(date('Y-m', time()) . '-01 00:00:00') - 86400);
    
    //-2月一号
    echo date('Y-m-01', strtotime('-2 month'));
    
    //-2月最后一天
    echo date("Y-m-d",strtotime(date('Y-m-01', strtotime('-2 month'))) - 86400);
    
    //上月今天
    echo date("Y-m-d", strtotime('-1 month'));
    
    //12月第二个周日
    echo date("Y-m-d", strtotime("Second Monday of ".date("Y-12")));
    
  • 相关阅读:
    设计模式学习笔记一
    linux学习记录(一)
    eclipse插件集合
    什么叫反向代理?
    shiro学习四
    shiro学习三
    shiro学习二
    第二次作业
    第一次作业
    自我介绍
  • 原文地址:https://www.cnblogs.com/William364248886/p/12028289.html
Copyright © 2011-2022 走看看