最近在做一个关于日程表的项目,给出一个开始时间和一个结束时间,需要列出这个时间段内的日期列表并同时判断是周几。经过研究,得出如下方法,和大家共享,方便有需要的朋友。
先贴一下此次需求的效果图:
下面是具体的代码片段:
/* *参数分别是开始时间戳,结束时间戳 */ function timeList($beginTimeStamp,$endTimeStamp){ if(!is_numeric($beginTimeStamp)||!is_numeric($endTimeStamp)||($endTimeStamp<=$beginTimeStamp)) return ''; $tmp=array(); for($i=$beginTimeStamp;$i<=$endTimeStamp;$i+=(24*3600)){ $tmp['timeStampList'][]=$i; $tmp['dayList'][]=date('Y年m月d日',$i); $tmp['dayWeek'][]=getWeek($i); } return $tmp; } function getWeek($timestamp){ $timestamp=date('w',$timestamp); $str='';//http://www.phpernote.com/php-function/969.html switch($timestamp){ case '0': $str.='周日'; break; case '1': $str.='周一'; break; case '2': $str.='周二'; break; case '3': $str.='周三'; break; case '4': $str.='周四'; break; case '5': $str.='周五'; break; case '6': $str.='周六'; break; } return $str; }
您可能感兴趣的文章
- php获取某段时间内每个月的方法,返回由这些月份组成的数组
- php 获取今日、昨日、上周、本月的起始时间戳和结束时间戳的方法
- PHP获取当前日期前30天的日期列表
- 为什么程序员估算的时间和项目实际完成的时间总有误差
- PHP实现即时将结果输出到浏览器
- php中date时间相差8个小时的解决办法
- php提取身份证号码中的生日日期以及验证是否为未成年人的函数
- php获取内容中的所有图片列表并输出的方法

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

WebStorm Mac version
Useful JavaScript development tools