Heim php教程 php手册 PHP-Funktion zum Abrufen des Startzeitstempels des aktuellen Jahres, Monats und Tages sowie des Startzeitstempels des nächsten Jahres, Monats und Tages

PHP-Funktion zum Abrufen des Startzeitstempels des aktuellen Jahres, Monats und Tages sowie des Startzeitstempels des nächsten Jahres, Monats und Tages

Sep 09, 2016 am 08:13 AM

1. Zeitstempel des aktuellen Jahres

2. Zeitstempel des aktuellen Monats

3. Der Zeitstempel des aktuellen Tages

4. Startzeitstempel des nächsten Jahres

5. Der Startzeitstempel des nächsten Monats

6. Der Startzeitstempel von morgen

7. Aktueller Zeitstempel

Funktionscode:

<span style="color: #008000;">/*</span><span style="color: #008000;">*
 * 获取时间戳
 * $Ymd = Y 年
 * $Ymd = m 月
 * $Ymd = d 日
 * $Ymd = NULL 当前时间戳
 * $xia = true 是否取下次开始时间戳:取下年开始时间戳 或者下月开始时间戳  或者明日开始时间戳
 </span><span style="color: #008000;">*/</span>
<span style="color: #0000ff;">function</span> getTime(<span style="color: #800080;">$Ymd</span>=<span style="color: #0000ff;">NULL</span>,<span style="color: #800080;">$xia</span>=<span style="color: #0000ff;">false</span><span style="color: #000000;">){
    </span><span style="color: #0000ff;">if</span>(<span style="color: #800080;">$Ymd</span>=='Y' && <span style="color: #800080;">$xia</span>==<span style="color: #0000ff;">true</span><span style="color: #000000;">){
        </span><span style="color: #008000;">//</span><span style="color: #008000;">取下个年度开始时间戳</span>
        <span style="color: #0000ff;">return</span> <span style="color: #008080;">strtotime</span>((<span style="color: #008080;">date</span>('Y',<span style="color: #008080;">time</span>())+1).'-01-01 00:00:00'<span style="color: #000000;">);
    }
    </span><span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$Ymd</span>=='Y'<span style="color: #000000;">){
        </span><span style="color: #008000;">//</span><span style="color: #008000;">取本年度开始时间戳</span>
        <span style="color: #0000ff;">return</span> <span style="color: #008080;">strtotime</span>(<span style="color: #008080;">date</span>('Y',<span style="color: #008080;">time</span>()).'-01-01 00:00:00'<span style="color: #000000;">);
    }
    </span><span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$Ymd</span>=='m' && <span style="color: #800080;">$xia</span>==<span style="color: #0000ff;">true</span><span style="color: #000000;">){
        </span><span style="color: #008000;">//</span><span style="color: #008000;">取下个月度开始时间戳</span>
        <span style="color: #800080;">$xiayue_nianfen</span>    =    <span style="color: #008080;">date</span>('Y',<span style="color: #008080;">time</span><span style="color: #000000;">());
        </span><span style="color: #800080;">$xiayue_yuefen</span>    =    <span style="color: #008080;">date</span>('m',<span style="color: #008080;">time</span><span style="color: #000000;">());
        </span><span style="color: #0000ff;">if</span>(<span style="color: #800080;">$xiayue_yuefen</span>==12<span style="color: #000000;">){
            </span><span style="color: #800080;">$xiayue_nianfen</span>    +=    1;    <span style="color: #008000;">//</span><span style="color: #008000;">如果月份等于12月,那么下月年份+1</span>
            <span style="color: #800080;">$xiayue_yuefen</span>    =    1;    <span style="color: #008000;">//</span><span style="color: #008000;">如果月份等于12月,那么下月月份=1月</span>
<span style="color: #000000;">        }
        </span><span style="color: #0000ff;">else</span><span style="color: #000000;">{
            </span><span style="color: #800080;">$xiayue_yuefen</span>    +=    1;    <span style="color: #008000;">//</span><span style="color: #008000;">如果月份不是12月,那么在当前月份上+1</span>
<span style="color: #000000;">        }
        </span><span style="color: #0000ff;">return</span> <span style="color: #008080;">strtotime</span>(<span style="color: #800080;">$xiayue_nianfen</span>.'-'.<span style="color: #800080;">$xiayue_yuefen</span>.'-01 00:00:00'<span style="color: #000000;">);
    }
    </span><span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$Ymd</span>=='m'<span style="color: #000000;">){
        </span><span style="color: #008000;">//</span><span style="color: #008000;">取本月度开始时间戳</span>
        <span style="color: #0000ff;">return</span> <span style="color: #008080;">strtotime</span>(<span style="color: #008080;">date</span>('Y-m',<span style="color: #008080;">time</span>()).'-01 00:00:00'<span style="color: #000000;">);
    }
    </span><span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$Ymd</span>=='d' && <span style="color: #800080;">$xia</span>==<span style="color: #0000ff;">true</span><span style="color: #000000;">){
        </span><span style="color: #008000;">//</span><span style="color: #008000;">取明日开始时间戳</span>
        <span style="color: #0000ff;">return</span> <span style="color: #008080;">strtotime</span>(<span style="color: #008080;">date</span>('Y-m-d',<span style="color: #008080;">time</span>()).' 00:00:00')+86400<span style="color: #000000;">;
    }
    </span><span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$Ymd</span>=='d'<span style="color: #000000;">){
        </span><span style="color: #008000;">//</span><span style="color: #008000;">取今日开始时间戳</span>
        <span style="color: #0000ff;">return</span> <span style="color: #008080;">strtotime</span>(<span style="color: #008080;">date</span>('Y-m-d',<span style="color: #008080;">time</span>()).' 00:00:00'<span style="color: #000000;">);
    }
    </span><span style="color: #0000ff;">else</span><span style="color: #000000;">{
        </span><span style="color: #008000;">//</span><span style="color: #008000;">取当前时间戳</span>
        <span style="color: #0000ff;">return</span> <span style="color: #008080;">time</span><span style="color: #000000;">();
    }
}</span>
Nach dem Login kopieren

Rufvorwahl:

getTime('Y');        <span style="color: #008000;">//</span><span style="color: #008000;">当前年的时间戳</span>
getTime('m');        <span style="color: #008000;">//</span><span style="color: #008000;">当前月的时间戳</span>
getTime('d');        <span style="color: #008000;">//</span><span style="color: #008000;">当前日的时间戳</span>
getTime('Y',<span style="color: #0000ff;">true</span>);    <span style="color: #008000;">//</span><span style="color: #008000;">明年的时间戳</span>
getTime('m',<span style="color: #0000ff;">true</span>);    <span style="color: #008000;">//</span><span style="color: #008000;">下月的时间戳</span>
getTime('d',<span style="color: #0000ff;">true</span>);    <span style="color: #008000;">//</span><span style="color: #008000;">明日的时间戳</span>
getTime();            <span style="color: #008000;">//</span><span style="color: #008000;">当前的时间戳</span>
Nach dem Login kopieren

Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn

Heiße KI -Werkzeuge

Undresser.AI Undress

Undresser.AI Undress

KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover

AI Clothes Remover

Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool

Undress AI Tool

Ausziehbilder kostenlos

Clothoff.io

Clothoff.io

KI-Kleiderentferner

AI Hentai Generator

AI Hentai Generator

Erstellen Sie kostenlos Ai Hentai.

Heißer Artikel

R.E.P.O. Energiekristalle erklärten und was sie tun (gelber Kristall)
3 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Beste grafische Einstellungen
3 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. So reparieren Sie Audio, wenn Sie niemanden hören können
3 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: Wie man alles in Myrise freischaltet
4 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌

Heiße Werkzeuge

Notepad++7.3.1

Notepad++7.3.1

Einfach zu bedienender und kostenloser Code-Editor

SublimeText3 chinesische Version

SublimeText3 chinesische Version

Chinesische Version, sehr einfach zu bedienen

Senden Sie Studio 13.0.1

Senden Sie Studio 13.0.1

Leistungsstarke integrierte PHP-Entwicklungsumgebung

Dreamweaver CS6

Dreamweaver CS6

Visuelle Webentwicklungstools

SublimeText3 Mac-Version

SublimeText3 Mac-Version

Codebearbeitungssoftware auf Gottesniveau (SublimeText3)