本类主要用于获取制定时间所在的周一、周日、上周一、上周日、月初、月底、上月初、上月底
<?php class datefl{ /** * 本周一 * @param int $timestamp 某个月的某一个时间戳,默认为当前时间 * @param string $date 日期格式 * @param bool|true $zero 时间是否归零到凌晨零点 * @return bool|int|string */ static public function thisMonday($timestamp=0,$date='',$zero=true){ //如果未设置时间,则使用当前时间 $timestamp || $timestamp = time(); //周一的时间 $time = $timestamp-86400*(date('N',$timestamp)-1); //归零处理 $zero && $time = self::_zero($time); //如果设置了日期格式,按格式返回 return $date ? date($date,$time) : $time; } /** * 本周日 * @param int $timestamp 某个月的某一个时间戳,默认为当前时间 * @param string $date 日期格式 * @param bool|true $zero 时间是否归零到凌晨零点 * @return bool|int|string */ static public function thisSunday($timestamp=0,$date='',$zero=true){ //如果未设置时间,则使用当前时间 $timestamp || $timestamp = time(); //周日 $time = $timestamp+86400*(7-date('N',$timestamp)); //归零处理 $zero && $time = self::_zero($time); //如果设置了日期格式,按格式返回 return $date ? date($date,$time) : $time; } /** * 上周一 * @param int $timestamp 某个月的某一个时间戳,默认为当前时间 * @param string $date 日期格式 * @param bool|true $zero 时间是否归零到凌晨零点 * @return bool|int|string */ static public function lastMonday($timestamp=0,$date='',$zero=true){ //如果未设置时间,则使用当前时间 $timestamp || $timestamp = time(); //上周同一时间 $timestamp = $timestamp-86400*7; //周一的时间 $time = $timestamp-86400*(date('N',$timestamp)-1); //归零处理 $zero && $time = self::_zero($time); //如果设置了日期格式,按格式返回 return $date ? date($date,$time) : $time; } /** * 上个星期天 * @param int $timestamp 某个月的某一个时间戳,默认为当前时间 * @param string $date 日期格式 * @param bool|true $zero 时间是否归零到凌晨零点 * @return bool|int|string */ static public function lastSunday($timestamp=0,$date='',$zero=true){ //如果未设置时间,则使用当前时间 $timestamp || $timestamp = time(); //上周同一时间 $timestamp = $timestamp-86400*7; //周日 $time = $timestamp+86400*(7-date('N',$timestamp)); //归零处理 $zero && $time = self::_zero($time); //如果设置了日期格式,按格式返回 return $date ? date($date,$time) : $time; } /** * 这个月的第一天 * @param int $timestamp 某个月的某一个时间戳,默认为当前时间 * @param string $date 日期格式 * @param bool|true $zero 时间是否归零到凌晨零点 * @return bool|int|string */ static public function monthFirstDay($timestamp=0,$date='',$zero=true){ //如果未设置时间,则使用当前时间 $timestamp || $timestamp = time(); //周一的时间 $time = mktime(date('H',$timestamp),date('i',$timestamp),date('s',$timestamp),date('m',$timestamp),1,date('Y',$timestamp)); //归零处理 $zero && $time = self::_zero($time); //如果设置了日期格式,按格式返回 return $date ? date($date,$time) : $time; } /** * 这个月的最后一天 * @param int $timestamp 某个月的某一个时间戳,默认为当前时间 * @param string $date 日期格式 * @param bool|true $zero 时间是否归零到凌晨零点 * @return bool|int|string */ static public function monthLastDay($timestamp=0,$date='',$zero=true){ //如果未设置时间,则使用当前时间 $timestamp || $timestamp = time(); //周一的时间 $time = mktime(date('H',$timestamp),date('i',$timestamp),date('s',$timestamp),date('m',$timestamp),date('t',$timestamp),date('Y',$timestamp)); //归零处理 $zero && $time = self::_zero($time); //如果设置了日期格式,按格式返回 return $date ? date($date,$time) : $time; } /** * 上个月的第一天 * @param int $timestamp 某个月的某一个时间戳,默认为当前时间 * @param string $date 日期格式 * @param bool|true $zero 时间是否归零到凌晨零点 * @return bool|int|string */ static public function lastMonthFirstDay($timestamp=0,$date='',$zero=true){ //如果未设置时间,则使用当前时间 $timestamp || $timestamp = time(); //周一的时间 $time = mktime(date('H',$timestamp),date('i',$timestamp),date('s',$timestamp),date('m',$timestamp)-1,1,date('Y',$timestamp)); //归零处理 $zero && $time = self::_zero($time); //如果设置了日期格式,按格式返回 return $date ? date($date,$time) : $time; } /** * 上个月的最后一天 * @param int $timestamp 某个月的某一个时间戳,默认为当前时间 * @param string $date 日期格式 * @param bool|true $zero 时间是否归零到凌晨零点 * @return bool|int|string */ static public function lastMonthLastDay($timestamp=0,$date='',$zero=true){ //如果未设置时间,则使用当前时间 !$timestamp || $timestamp = time(); //上月第一天的当前时间 $timestamp = mktime(date('H',$timestamp),date('i',$timestamp),date('s',$timestamp),date('m',$timestamp)-1,1,date('Y',$timestamp)); //取得最后一天时间 $time = mktime(date('H',$timestamp),date('i',$timestamp),date('s',$timestamp),date('m',$timestamp),date('t',$timestamp),date('Y',$timestamp)); //归零处理 $zero && $time = self::_zero($time); //如果设置了日期格式,按格式返回 return $date ? date($date,$time) : $time; } /** * 时间归零,回到当天的00:00:00 * @param $timestamp * @return int */ static private function _zero($timestamp) { return strtotime(date('Y-m-d',$timestamp)); } } $t = time(); echo '<br>本周星期一:'; echo datefl::thisMonday($t,'Y-m-d H:i:s'); echo '<br>本周星期天:'; echo datefl::thisSunday($t,'Y-m-d H:i:s'); echo '<br>上周星期一:'; echo datefl::lastMonday($t,'Y-m-d H:i:s'); echo '<br>上周星期天:'; echo datefl::lastSunday($t,'Y-m-d H:i:s'); echo '<br>本月第一天:'; echo datefl::monthFirstDay($t,'Y-m-d H:i:s'); echo '<br>本月最后一天:'; echo datefl::monthLastDay($t,'Y-m-d H:i:s'); echo '<br>上月第一天:'; echo datefl::lastMonthFirstDay($t,'Y-m-d H:i:s'); echo '<br>上月最后一天:'; echo datefl::lastMonthLastDay($t,'Y-m-d H:i:s');

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

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

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.

SublimeText3 Chinese version
Chinese version, very easy to use