更新時間:2018年08月06日15時01分 來源:傳智播客 瀏覽次數(shù):
1.獲取上個月第一天及最后一天.
echo date('Y-m-01', strtotime('-1 month'));
echo "
";
echo date('Y-m-t', strtotime('-1 month'));
echo "
";
2.獲取當(dāng)月第一天及最后一天.
$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.獲取當(dāng)天年份、月份、日及天數(shù).
echo " 本月共有:".date("t")."天";
echo " 當(dāng)前年份".date('Y');
echo " 當(dāng)前月份".date('m');
echo " 當(dāng)前幾號".date('d');
echo "
";
4.使用函數(shù)及數(shù)組來獲取當(dāng)月第一天及最后一天,比較實(shí)用,出自網(wǎng)友.
function getthemonth($date)
{
$firstday = date('Y-m-01', strtotime($date));
$lastday = date('Y-m-d', strtotime("$firstday +1 month -1 day"));
return array($firstday,$lastday);
}
$today = date("Y-m-d");
$day=getthemonth($today);
echo "當(dāng)月的第一天: ".$day[0]." 當(dāng)月的最后一天: ".$day[1];
echo "
";
作者:傳智播客PHP培訓(xùn)學(xué)院
首發(fā):http://php.itcast.cn/