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));
|