《PHP編程:PHP簡(jiǎn)單獲取上月、本月、近15天、近30天的方法示例》要點(diǎn):
本文介紹了PHP編程:PHP簡(jiǎn)單獲取上月、本月、近15天、近30天的方法示例,希望對(duì)您有用。如果有疑問,可以聯(lián)系我們。
PHP學(xué)習(xí)本文實(shí)例講述了PHP簡(jiǎn)單獲取上月、本月、近15天、近30天方法.分享給大家供大家參考,具體如下:
PHP學(xué)習(xí)
/**
* 獲取統(tǒng)計(jì)時(shí)間
* @param $type
* 1 上月
* 2 本月
* 3 近15天
* 4 近30天
* @return array
*/
function getDateInfo($type)
{
$data = array(
array(
'firstday' => date('Ym01', strtotime('-1 month')),
'lastday' => date('Ymt', strtotime('-1 month')),
),
array(
'firstday' => date('Ym01', strtotime(date("Y-m-d"))),
'lastday' => date('Ymd', strtotime((date('Ym01', strtotime(date("Y-m-d")))) . " +1 month -1 day")),
),
array(
'firstday' => date('Ymd', strtotime("-15 day")),
'lastday' => date('Ymd', strtotime('-1 day')),
),
array(
'firstday' => date('Ymd', strtotime("-30 day")),
'lastday' => date('Ymd', strtotime('-1 day')),
),
);
return is_null($type) ? $data : $data[$type-1];
}
print_r(getDateInfo(1));//獲取上個(gè)月第一天與最后一天
PHP學(xué)習(xí)運(yùn)行結(jié)果:
PHP學(xué)習(xí)
Array
(
[firstday] => 20170601
[lastday] => 20170630
)
PHP學(xué)習(xí)PS:這里再為大家推薦幾款時(shí)間及日期相關(guān)工具供大家參考使用:
PHP學(xué)習(xí)在線日期/天數(shù)計(jì)算器:
http://tools.jb51.net/jisuanqi/date_jisuanqi
PHP學(xué)習(xí)在線日期計(jì)算器/相差天數(shù)計(jì)算器:
http://tools.jb51.net/jisuanqi/datecalc
PHP學(xué)習(xí)在線日期天數(shù)差計(jì)算器:
http://tools.jb51.net/jisuanqi/onlinedatejsq
PHP學(xué)習(xí)Unix時(shí)間戳(timestamp)轉(zhuǎn)換工具:
http://tools.jb51.net/code/unixtime
PHP學(xué)習(xí)更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php日期與時(shí)間用法總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《PHP基本語法入門教程》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
PHP學(xué)習(xí)希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助.
轉(zhuǎn)載請(qǐng)注明本頁網(wǎng)址:
http://www.snjht.com/jiaocheng/542.html