<?PHPclass Time{ /** * Returns the timestamp of the start and end of today * * @return Array*/ Public Static functiontoday () {return [ Mktime(0, 0, 0,Date(' m '),Date(' d '),Date(' Y ')),Mktime(23, 59, 59,Date(' m '),Date(' d '),Date(' Y ')) ]; } /** * Returns the timestamp of the start and end of yesterday * * @return Array*/ Public Static functionyesterday () {$yesterday=Date(' d ')-1; return [ Mktime(0, 0, 0,Date(' m '),$yesterday,Date(' Y ')),Mktime(23, 59, 59,Date(' m '),$yesterday,Date(' Y ')) ]; } /** * Returns the timestamp of the start and end of the week * * @return Array*/ Public Static functionWeek () {$timestamp= Time(); return [ Strtotime(Date(' y-m-d ',Strtotime("This Week Monday",$timestamp))),Strtotime(Date(' y-m-d ',Strtotime("This Week Sunday",$timestamp)) + 24 * 3600-1 ]; } /** * return last week start and end timestamp * * @return array*/ Public Static functionLastweek () {$timestamp= Time(); return [ Strtotime(Date(' y-m-d ',Strtotime("Last week Monday",$timestamp))),Strtotime(Date(' y-m-d ',Strtotime("Last week Sunday",$timestamp)) + 24 * 3600-1 ]; } /** * returns the start and end timestamp of the month * * @return Array*/ Public Static functionMonth$everyDay=false) { return [ Mktime(0, 0, 0,Date(' m '), 1,Date(' Y ')),Mktime(23, 59, 59,Date(' m '),Date(' t '),Date(' Y ')) ]; } /** * Returns the timestamp of the beginning and end of the month * * @return Array*/ Public Static functionLastmonth () {$begin=Mktime(0, 0, 0,Date(' m ')-1, 1,Date(' Y ')); $end=Mktime(23, 59, 59,Date(' m ')-1,Date(' t ',$begin),Date(' Y ')); return[$begin,$end]; } /** * returns the start and end timestamp of the year * * @return array*/ Public Static functionYear () {return [ Mktime(0, 0, 0, 1, 1,Date(' Y ')),Mktime(23, 59, 59, 12, 31,Date(' Y ')) ]; } /** * Returns the timestamp of the beginning and end of last year * * @return array*/ Public Static functionLastYear () {$year=Date(' Y ')-1; return [ Mktime(0, 0, 0, 1, 1,$year),Mktime(23, 59, 59, 12, 31,$year) ]; } Public Static functiondayof () {}/** * Get a few days before 0 to now/end of yesterday timestamp * * @param int $day days * @param bool $now return now or yesterday end timestamp * @return Array */ Public Static functionDaytonow ($day= 1,$now=true) { $end= Time(); if(!$now) { List($foo,$end) = self::yesterday (); } return [ Mktime(0, 0, 0,Date(' m '),Date(' d ')-$day,Date(' Y ')),$end ]; } /** * Returns the timestamp of a few days ago * * @param int $day * @return int*/ Public Static functionDaysago ($day= 1) { $nowTime= Time(); return $nowTime-Self::d aystosecond ($day); } /** * returns timestamp after a few days * * @param int $day * @return int*/ Public Static functionDaysafter ($day= 1) { $nowTime= Time(); return $nowTime+ Self::d aystosecond ($day); } /** * Number of days converted to seconds * * @param int $day * @return int*/ Public Static functionDaystosecond ($day= 1) { return $day* 86400; } /** * number of weeks converted to seconds * * @param int $week * @return int*/ Public Static functionWeektosecond ($week= 1) { returnSelf::d aystosecond () * 7 *$week; } Private Static functionstarttimetoendtime () {}}?>
PHP gets today, yesterday, this week, last week, this month, and so on. Common start timestamp and end timestamp time processing class: