php日周月排行版
阿新 • • 發佈:2019-02-02
-
PHP 獲取當前天的開始時間、結束時間:
PHP mktime()函式,返回一個指定日期的Unix時間戳。
$t = time();
$start_time = mktime(0,0,0,date("m",$t),date("d",$t),date("Y",$t)); //當天開始時間
$end_time = mktime(23,59,59,date("m",$t),date("d",$t),date("Y",$t)); //當天結束時間獲取當前月的開始時間、結束時間:
$date = date("Y-m-d");
$firstday = date('Y-m-01', strtotime($date));
$lastday = date('Y-m-d', strtotime("$firstday +1 month -1 day"));$firstday = date('Y-m-01 00:00:00', strtotime($date)); //本月第一天
$lastday = date('Y-m-d 23:59:59', strtotime("$firstday +1 month -1 day")); //本月最後一天
其他時間:
echo " 本月共有:".date("t")."天";
echo " 當前年份".date('Y');
echo " 當前月份".date('m');
echo " 當前幾號".date('d'); - <?php
-
echodate("Ymd",strtotime("now")),
- echodate("Ymd",strtotime("-1 week Monday")), "\n";
- echodate("Ymd",strtotime("-1 week Sunday")), "\n";
- echodate("Ymd",strtotime("+0 week Monday")), "\n";
- echodate("Ymd",strtotime("+0 week Sunday")), "\n";
- echo"*********第幾個月:";
- echodate('n');
-
echo"*********本週周幾:"
- echodate("w");
- echo"*********本月天數:";
- echodate("t");
- echo"*********";
- echo'<br>上週起始時間:<br>';
- echodate("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1-7,date("Y"))),"\n";
- echodate("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7-7,date("Y"))),"\n";
- echo'<br>本週起始時間:<br>';
- echodate("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1,date("Y"))),"\n";
- echodate("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7,date("Y"))),"\n";
- //從第幾周找出該周的開始日期和結束日期
- $dayNumber = date('W') * 7;
- $weekDayNumber = date("w", mktime(0, 0, 0, 1, $dayNumber, date("Y")));//當前周的第幾天
- $startNumber = $dayNumber - $weekDayNumber;
- echodate("Y-m-d", mktime(0, 0, 0, 1, $startNumber + 1, date("Y")));//開始日期
- echodate("Y-m-d", mktime(0, 0, 0, 1, $startNumber + 7, date("Y")));//結束日期
- echo'<br>上月起始時間:<br>';
- echodate("Y-m-d H:i:s",mktime(0, 0 , 0,date("m")-1,1,date("Y"))),"\n";
- echodate("Y-m-d H:i:s",mktime(23,59,59,date("m") ,0,date("Y"))),"\n";
- echo'<br>本月起始時間:<br>';
- echodate("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),1,date("Y"))),"\n";
- echodate("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>';
- echodate('Y-m-d H:i:s', mktime(0, 0, 0,$season*3-3+1,1,date('Y'))),"\n";
- echodate('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>';
- echodate('Y-m-d H:i:s', mktime(0, 0, 0,$season*3-3+1,1,date('Y'))),"\n";
- echodate('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";
- ?>