首頁 繪圖設計 工作閒聊 比賽活動 美術討論 標籤 圖片
回上頁
上個月完整 UNIXTIME 範圍: mktime, time, date, strtotime PHP Example
service(staff) 2014/10/7 15:01

Last Month EPOCH time coverage 上個月完整的 UNIX TIME 範圍 (PHP)




PHP Code Examples which count unixtime of
first day of last month (00:00:00) to last day of last month (23:59:59)

e.g. 2014/12/01 00:00:00 ~ 2014/12/31 23:59:59

代碼:


/* (a): Count timestamp diff from 00:00:00 ~ now */
/* (a): 今天 00:00:00 ~ 目前的 UNIX timestamp */

$gap_epoch = time() - mktime('00', '00', '00', date('n', time()), date('j', time()), date('Y', time()));
echo $gap_epoch;

/* (b) First Day of Last Month 00:00:00, e.g. 2014-12-31 00:00:00 */
/* (b) 上個月「第一天」的 00:00:00 */

$unixtime_last_month_begin = strtotime('first day of last month') - $gap_epoch;
echo date('Y-m-d H:i:s', $unixtime_last_month_begin);

/* (c) Last Day of Last Month 00:00:00  e.g. 2014-12-31 23:59:59 */
/* (c) 上個月「最後一天」的 23:59:59 */

$unixtime_last_month_end   = strtotime('last day of last month') - $gap_epoch + 86400 - 1;
echo date('Y-m-d H:i:s', $unixtime_last_month_end);

/* (d) Convert to UNIX TIME again from String  */
echo strtotime(date('Y-m-d H:i:s', $unixtime_last_month_begin));
echo strtotime(date('Y-m-d H:i:s', $unixtime_last_month_end));






(4,355 views)
[更多討論] 討論區 Windows, Linux, Perl, PHP, C/C++, Driver, Web 理論、應用、硬體、軟體
回上頁

"上個月完整 UNIXTIME 範圍: mktime, time, date, strtotime PHP Example" 傳統頁面(電腦版)

首頁 繪圖設計 工作閒聊 比賽活動 美術討論 標籤 圖片
傳統桌面版 [ 登入/註冊 ]
© Vovo2000.com Mobile Version 小哈手機版 2024