search
Homephp教程php手册php+js+时间戳比较,输出不同内容

php+js+时间戳比较,输出不同内容

Jun 06, 2016 pm 07:41 PM
phpdifferentcontentfunctiontimeCompareoutput

PHP函数 function switchInfor(infor1,infor2){ $mor_time = date(Y-m-d). 8:00:00; $nin_time = date(Y-m-d).17:00:00; $n_time = date(Y-m-d H:i:s); $mor_time_format = strtotime($mor_time); $nin_time_format = strtotime($nin_time); $n_time_format

PHP函数

function switchInfor(infor1,infor2){

    $mor_time = date("Y-m-d")." 8:00:00";

    $nin_time = date("Y-m-d")."17:00:00";

    $n_time = date("Y-m-d H:i:s");

    $mor_time_format = strtotime($mor_time);

    $nin_time_format = strtotime($nin_time);

    $n_time_format     = strtotime($n_time);
    
    if(($mor_time_format-$n_time_format)>=0&&($n_time_format-$nin_time_format)>=0)
        return infor1;
    else
        return infor2;

}

JS函数

    function switchInfor(infor1,infor2,idinfor){

    //infor1  早上8点到晚上5之间的信息
    //infor2  其他时间内的信息
    //idinfor 输出位置的ID
            

        var myDate = new Date();                           //Date对象

        var Year = myDate.getFullYear();              

        var Mouth = myDate.getMonth();    

        var Dat = myDate.getDate();                    
        

        var mor_time = new Date(Year,Mouth,Dat,8,0,0).getTime();

        var nin_time = new Date(Year,Mouth,Dat,17,0,0).getTime();

        var now_time = myDate.getTime();

        //alert(mor_time+'-'+nin_time+'-'+now_time);

        if((now_time-mor_time>=0)&&(nin_time-now_time)>=0)
        {
            document.getElementById(idinfor).innerHTML=infor1;
        }
        else
        {
            document.getElementById(idinfor).innerHTML=infor2;
        }
    }
Statement
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

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

MantisBT

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.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor