惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

月光博客
月光博客
Martin Fowler
Martin Fowler
博客园_首页
量子位
T
Tailwind CSS Blog
博客园 - Franky
G
Google Developers Blog
D
DataBreaches.Net
Vercel News
Vercel News
B
Blog
Recent Announcements
Recent Announcements
S
SegmentFault 最新的问题
M
MIT News - Artificial intelligence
爱范儿
爱范儿
博客园 - 【当耐特】
The Cloudflare Blog
H
Help Net Security
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
C
Check Point Blog
有赞技术团队
有赞技术团队
Microsoft Security Blog
Microsoft Security Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 工具人Kim哥

mysql数据库备份命令大全 Vue获取url网址参数的两种方法 在vscode下编译vue神坑40% building 过不去 vue元素对齐方式 一个身高体重测量工具(BMI测量工具) HTML代码格式化实现方式 一个不错的常用小工具站点 Fiddler使用 不错的SDL源码分析 unity3d中获得物体的size PPT文化 Unity消息 Unity3D中的UnitySendMessage方法的使用 Android性能优化之渲染 问题记录 VS2012项目中使用CocoStudio相关文件的设置 国际金融基础知识 Nutch 安装文档 sed linux 命令
PHP获取本周的每一天的时间
工具人Kim哥 · 2023-10-13 · via 博客园 - 工具人Kim哥

1.PHP获取未来一周的时间

public function getWeek()
{
    for($i=0;$i<7;$i++)
    {
        $arr[$i]=date('Y-m-d',strtotime(date('Y-m-d').'-'.$i.'day'));
    }

    return json($arr);
}    

2.PHP获取本周每一天的时间

public function getDay()
{
$timestr = time(); //当前时间戳
$now_day = date('w',$timestr); //当前是周几

//获取周一
$monday_str = $timestr - ($now_day-1)*60*60*24;
$monday = date('Y-m-d', $monday_str);

//获取周日
$sunday_str = $timestr + (7-$now_day)*60*60*24;
$sunday = date('Y-m-d', $sunday_str);

for($i=0;$i<7;$i++)
{
$arr[$i]=date('Y-m-d',strtotime($monday.'+'.$i.'day'));
}
return json($arr);
// echo "星期一: $monday\n";
// echo "星期天: $sunday\n";
}

效果:

["2023-11-11","2023-11-12","2023-11-13","2023-11-14","2023-11-15","2023-11-16","2023-11-17"]