php+js+时间戳比较,输出不同内容
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;
}
}
上一篇: MySQL查询优化程序_MySQL
下一篇: 数据库设计之EAV(实体、属性、值)