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

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

WBOY
Release: 2016-06-06 19:41:38
Original
1096 people have browsed it

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;
        }
    }
source:php.cn
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template