Home 类库下载 PHP类库 PHP function to get the starting timestamp of the current year, month, and day and the starting timestamp of the next year, month, and day

PHP function to get the starting timestamp of the current year, month, and day and the starting timestamp of the next year, month, and day

Oct 10, 2016 am 10:52 AM

PHP function to get the start timestamp of the current year, month, and day and the start timestamp of the next year, month, and day

1. The timestamp of the current year

2. The timestamp of the current month

3. The timestamp of the current day

4. Next year’s start timestamp

5. Next month’s start timestamp

6. Tomorrow’s start timestamp

7. Current timestamp

Function code:

/**
 * 获取时间戳
 * $Ymd = Y 年
 * $Ymd = m 月
 * $Ymd = d 日
 * $Ymd = NULL 当前时间戳
 * $xia = true 是否取下次开始时间戳:取下年开始时间戳 或者下月开始时间戳  或者明日开始时间戳
 */
function getTime($Ymd=NULL,$xia=false){
    if($Ymd=='Y' && $xia==true){
        //取下个年度开始时间戳
        return strtotime((date('Y',time())+1).'-01-01 00:00:00');
    }
    else if($Ymd=='Y'){
        //取本年度开始时间戳
        return strtotime(date('Y',time()).'-01-01 00:00:00');
    }
    else if($Ymd=='m' && $xia==true){
        //取下个月度开始时间戳
        $xiayue_nianfen    =    date('Y',time());
        $xiayue_yuefen    =    date('m',time());
        if($xiayue_yuefen==12){
            $xiayue_nianfen    +=    1;    //如果月份等于12月,那么下月年份+1
            $xiayue_yuefen    =    1;    //如果月份等于12月,那么下月月份=1月
        }
        else{
            $xiayue_yuefen    +=    1;    //如果月份不是12月,那么在当前月份上+1
        }
        return strtotime($xiayue_nianfen.'-'.$xiayue_yuefen.'-01 00:00:00');
    }
    else if($Ymd=='m'){
        //取本月度开始时间戳
        return strtotime(date('Y-m',time()).'-01 00:00:00');
    }
    else if($Ymd=='d' && $xia==true){
        //取明日开始时间戳
        return strtotime(date('Y-m-d',time()).' 00:00:00')+86400;
    }
    else if($Ymd=='d'){
        //取今日开始时间戳
        return strtotime(date('Y-m-d',time()).' 00:00:00');
    }
    else{
        //取当前时间戳
        return time();
    }
}
Copy after login

Calling code:

getTime('Y');        //当前年的时间戳
getTime('m');        //当前月的时间戳
getTime('d');        //当前日的时间戳
getTime('Y',true);    //明年的时间戳
getTime('m',true);    //下月的时间戳
getTime('d',true);    //明日的时间戳
getTime();            //当前的时间戳
Copy after login


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)