~~~
/**
* 生成從開始月份到結束月份的月份數組
* @param int $start 開始時間
* @param int $end 結束時間
*/
function monthList($start,$end){
$month_arr = array();
$start_timestamp = strtotime($start);
$end_timestamp = strtotime($end);
$start_timestamp = mktime(0, 0, 0, date("n", $start_timestamp), 1, date("Y", $start_timestamp));
$next_timestamp = $start_timestamp;
while ($next_timestamp <= $end_timestamp) {
$month_arr[] = date("Y-m", $next_timestamp);
$next_timestamp = mktime(0, 0, 0, date("n", $next_timestamp) + 1, date("j", $next_timestamp), date("Y", $next_timestamp));
};
return $month_arr;
}
~~~
* * * * *
~~~
//得到日期的上個月的今天,如strtotime('2016-10-20')返回得到2016-09-20
function last_month_today($time){
$last_month_time = mktime(date("G", $time), date("i", $time),
date("s", $time), date("n", $time), 0, date("Y", $time));
$last_month_t = date("t", $last_month_time);
if ($last_month_t < date("j", $time)) {
return date("Ymt H:i:s", $last_month_time);
}
return date(date("Ym", $last_month_time) . "d", $time);
}
~~~
* * * * *
~~~
/*
* 根據兩日期,獲取之間的日期列表
* $start_time 開始日期 格式20160701
* $end_time 結束日期 格式20160916
* */
function get_d_list($start_time,$end_time){
$start_time = strtotime($start_time);
$end_time = strtotime($end_time);
$date_list = array();
for($start_time;$start_time<=$end_time;$start_time=$start_time+3600*24){
$date_list[] = date('Ymd',$start_time);
}
return $date_list;
}
~~~
* * * * *
~~~
/**
* [顯示友好的時間格式 xx分鐘前 xx小時前 xx天 超過3天顯示正常時間]
* @param [type] $date [description]
* @return [type] [description]
*/
function dataStr($date){
if((time()-$date)<60*10){
//十分鐘內
echo '剛剛';
}elseif(((time()-$date)<60*60)&&((time()-$date)>=60*10)){
//超過十分鐘少于1小時
$s = floor((time()-$date)/60);
echo $s."分鐘前";
}elseif(((time()-$date)<60*60*24)&&((time()-$date)>=60*60)){
//超過1小時少于24小時
$s = floor((time()-$date)/60/60);
echo $s."小時前";
}elseif(((time()-$date)<60*60*24*3)&&((time()-$date)>=60*60*24)){
//超過1天少于3天內
$s = floor((time()-$date)/60/60/24);
echo $s."天前";
}else{
//超過3天
echo date("Y/m/d",$date);
}
}
~~~