PHP获取今天,昨天,本周,本月,季度,年份等特殊时间戳方法整理
warning:
这篇文章距离上次修改已过183天,其中的内容可能已经有所变动。
<?php
// 获取今天0点时间戳
$today = strtotime(date('Y-m-d 00:00:00'));
// 获取昨天0点时间戳
$yesterday = strtotime("-1 day", $today);
// 获取本周第一天(默认以星期日为第一天)时间戳
$beginWeek = strtotime("this week Monday");
// 获取本周最后一天时间戳
$endWeek = strtotime("next week Sunday");
// 获取本月第一天时间戳
$beginMonth = strtotime(date('Y-m-01 00:00:00'));
// 获取本月最后一天时间戳
$endMonth = strtotime(date('Y-m-t 23:59:59'));
// 获取当前季度第一天时间戳
$beginSeason = date('n') - date('n') % 3 + 1;
$beginSeason = strtotime(date('Y-') . $beginSeason . '-01 00:00:00');
// 获取当前季度最后一天时间戳
$endSeason = $beginSeason + 3 * 30 * 24 * 60 * 60;
// 获取年初第一天时间戳
$beginYear = strtotime(date('Y-01-01 00:00:00'));
// 获取年末最后一天时间戳
$endYear = strtotime(date('Y-12-31 23:59:59'));
?>
以上代码提供了获取特殊时间段时间戳的PHP函数示例,包括今天、昨天、本周、本月、季度和年份的开始和结束时间戳。
评论已关闭