|
发表于 2021-5-22 16:18:55
|
显示全部楼层
- <?php
- echo date("Ymd",strtotime("now")), "\n";
- echo date("Ymd",strtotime("-1 week Monday")), "\n";
- echo date("Ymd",strtotime("-1 week Sunday")), "\n";
- echo date("Ymd",strtotime("+0 week Monday")), "\n";
- echo date("Ymd",strtotime("+0 week Sunday")), "\n";
- echo "*********第几个月:";
- echo date('n');
- echo "*********本周周几:";
- echo date("w");
- echo "*********本月天数:";
- echo date("t");
- echo "*********";
- echo '<br>上周起始时间:<br>';
- echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1-7,date("Y"))),"\n";
- echo date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7-7,date("Y"))),"\n";
- echo '<br>本周起始时间:<br>';
- echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1,date("Y"))),"\n";
- echo date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7,date("Y"))),"\n";
- echo '<br>上月起始时间:<br>';
- echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m")-1,1,date("Y"))),"\n";
- echo date("Y-m-d H:i:s",mktime(23,59,59,date("m") ,0,date("Y"))),"\n";
- echo '<br>本月起始时间:<br>';
- echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),1,date("Y"))),"\n";
- echo date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("t"),date("Y"))),"\n";
- $season = ceil((date('n'))/3);//当月是第几季度
- echo '<br>本季度起始时间:<br>';
- echo date('Y-m-d H:i:s', mktime(0, 0, 0,$season*3-3+1,1,date('Y'))),"\n";
- echo date('Y-m-d H:i:s', mktime(23,59,59,$season*3,date('t',mktime(0, 0 , 0,$season*3,1,date("Y"))),date('Y'))),"\n";
- $season = ceil((date('n'))/3)-1;//上季度是第几季度
- echo '<br>上季度起始时间:<br>';
- echo date('Y-m-d H:i:s', mktime(0, 0, 0,$season*3-3+1,1,date('Y'))),"\n";
- echo date('Y-m-d H:i:s', mktime(23,59,59,$season*3,date('t',mktime(0, 0 , 0,$season*3,1,date("Y"))),date('Y'))),"\n";
- echo '<br>本年度起止时间:<br>';
- echo date('Y-m-d',strtotime(date("Y",time())."-1"."-1")); //本年开始
- echo date('Y-m-d',strtotime(date("Y",time())."-12"."-31")); //本年结束
复制代码- //php获取今日开始时间戳和结束时间戳
- $beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));
- $endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
- //php获取昨日起始时间戳和结束时间戳
- $beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
- $endYesterday=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
- //php获取上周起始时间戳和结束时间戳
- $beginLastweek=mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y'));
- $endLastweek=mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y'));
- //php获取本月起始时间戳和结束时间戳
- $beginThismonth=mktime(0,0,0,date('m'),1,date('Y'));
- $endThismonth=mktime(23,59,59,date('m'),date('t'),date('Y'));
复制代码
- 开发过程中,常用日期处理函数,时间戳处理函数等,如下讲解:
- <?php
- echo date('Y-m-d h:i:s',time());
- //运行结果(年月日时分秒,“-”间隔):2014-09-12 06:28:32
- echo date('Y-m-d',time());
- //运行结果(年月日,“-”间隔):2014-09-12
- echo date('Y-m-d',strtotime(date('Y-m-d', time()-86400)));
- //运行结果(当前日期前一天的年月日,“-”间隔):2014-09-11
- echo date('Ymd',time());
- //运行结果(年月日,无间隔):20140912
- echo date('m-d',time());
- //运行结果(月日,“-”间隔):09-12
- echo str_replace("-","月",date('m-d',time()-date('w',time())*86400))."日";
- //运行结果(月日,汉字显示间隔):09月12日
- echo date('w',time());
- //运行结果(星期几):5
- echo time();
- //运行结果(当前日期时间的秒数):1410503809
- echo strtotime(date('Y-m-d',time()));
- //运行结果(当前日期秒数,具体到天):1410503809
- echo date('Y-m-d',strtotime(date('Y-m-d', time()))-date('w',strtotime(date('Y-m-d', time())))*86400);
- //运行结果(当前日期所属自然周的起始日期即周日的日期,具体到天,“-”间隔):2014-09-07
复制代码
|
|