获取各时间段的时间戳,上月、当月、上周、当周、上日、今日
/**
* 获取时间段的开始、结束时间戳
* @param string $timetype 时间类型 yesmonth-上月 nowmonth-当月 yesday-上一天 nowday-今日 yesweek-上周 nowweek-上周
*/
function getFLtime($timetype){
switch ($timetype){
case 'yesmonth':
//计算上一月
$first = date('Y-m-d H:i:s', mktime(0, 0, 0, date('m') - 1, 1, date('Y')));
$last = date('Y-m-d 23:59:59', strtotime("$first +1 month -1 day"));
break;
case 'nowmonth':
$date = date("Y-m-d");
// 本月第一天
$first = date('Y-m-01 0:0:0', strtotime($date));
// 本月最后一天
$last = date('Y-m-d 23:59:59', strtotime("$first +1 month -1 day"));
break;
case 'yesday':
$first = date('Y-m-d 0:0:0',time()-3600*24);
$last = date('Y-m-d 23:59:59',strtotime($first));
break;
case 'nowday':
$first = date('Y-m-d 0:0:0',time());
$last = date('Y-m-d 23:59:59',strtotime($first));
break;
case 'yesweek':
$timestamp = time();
$first = date('Y-m-d H:i:s', strtotime("last week Monday", $timestamp));
$last = date('Y-m-d H:i:s', (strtotime(date('Y-m-d', strtotime("last week Sunday", $timestamp))) + 24 * 3600 - 1));
break;
case 'nowweek':
$timestamp = time();
$first = date('Y-m-d H:i:s', strtotime("this week Monday", $timestamp));
$last = date('Y-m-d H:i:s', (strtotime(date('Y-m-d H:i:s', strtotime("this week Sunday", $timestamp))) + 24 * 3600 - 1));
break;
default:
return false;
break;
}
return ['start'=>strtotime($first),'end'=>strtotime($last)];
}
?>
以上是获取各时间段的时间戳,上月、当月、上周、当周、上日、今日的详细内容。更多信息请关注PHP中文网其他相关文章!

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

热门话题

PHP 8的JIT编译通过将代码经常汇编为机器代码,从而增强了性能,从而使应用程序有益于大量计算并减少执行时间。

本文讨论了PHP中的对称和不对称加密,并比较了它们的适用性,性能和安全差异。对称加密速度更快,适合大量数据,而不对称的键交换则使用。

本文讨论了OWASP在PHP和缓解策略中的十大漏洞。关键问题包括注射,验证损坏和XSS,并提供用于监视和保护PHP应用程序的推荐工具。

本文讨论了MySQLI_QUERY()和MySQLI_Fetch_Assoc()在PHP中的MySQL数据库交互中的功能。它解释了他们的角色,差异,并提供了它们使用的实际例子。主要论点侧重于usin的好处

本文讨论了确保PHP文件上传的确保,以防止诸如代码注入之类的漏洞。它专注于文件类型验证,安全存储和错误处理以增强应用程序安全性。
