PHP gets today, yesterday, this week, last week, this month, and so on. Common start timestamp and end timestamp time processing class:

Source: Internet
Author: User

<?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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.