1.獲取上個月第一天及最後一天.
echo date('y-m-01', strtotime('-1 month'));
echo "
"; echo date('y-m-t', strtotime('-1 month'));
echo "
";2.獲取當月第一天及最後一天.
$begindate=date('y-m-01', strtotime(date("y-m-d")));
echo $begindate;
echo "
"; echo date('y-m-d', strtotime("$begindate +1 month -1 day"));
echo "
";3.獲取當天年份、月份、日及天數.
echo " 本月共有:".date("t")."天";
echo " 當前年份".date('y');
echo " 當前月份".date('m');
echo " 當前幾號".date('d');
echo "
";4.使用函式及陣列來獲取當月第一天及最後一天,比較實用
function getthemonth($date)
$today = date("y-m-d");
$day=getthemonth($today);
echo "當月的第一天: ".$day[0]." 當月的最後一天: ".$day[1];
echo "
";
<?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 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 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";
//從第幾周找出該週的開始日期和結束日期
$daynumber = date('w') * 7;
$weekdaynumber = date("w", mktime(0, 0, 0, 1, $daynumber, date("y")));//當前周的第幾天
$startnumber = $daynumber - $weekdaynumber;
echo date("y-m-d", mktime(0, 0, 0, 1, $startnumber + 1, date("y")));//開始日期
echo date("y-m-d", mktime(0, 0, 0, 1, $startnumber + 7, date("y")));//結束日期
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 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 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 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";
?>
PHP 日期格式化(獲取上月第一天 最後一天等)
1.獲取上個月第一天及最後一天.echo date y m 01 strtotime 1 month echo echo date y m t strtotime 1 month echo 2.獲取當月第一天及最後一天.begindate date y m 01 strtotime date y m...
js格式化日期 獲取當月最後一天 第一天
最近專案中使用了大量關於日期的操作遂將其整理如下 格式化日期 param fmt 日期型別 預設為年月日 yyyy mm dd date.prototype.format function fmt yyyy mm dd if y test fmt for var key in date return...
日期獲取本月第一天和最後一天
getfullyear 日期物件獲取年份 yyyy getmonth 獲取月份0 11 getdate 獲取一月中的第幾天 1 31 setdate num 傳數字設定本月日期第幾天 newdate year month,day,hours,可以傳字串或數字 newdate fullyear,mon...