[代码收集]高考倒计时

2014-08-11 20:09:42 -0400
<?php
header("content-type:text/html;charset=UTF-8");
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">';
echo '<html xmlns="http://www.w3.org/1999/xhtml">';
?>
<head>
<title>高考倒计时</title>
</head>
<body>
<?php
date_default_timezone_set("Asia/Shanghai");

$today=date("Y-m-d H:i:s");
$tmp1=explode(' ',$today);
$tmp1=explode('-',$tmp1[0]);//解析今天的年月日为数组
$Y=($tmp1[1]<6 || $tmp1[1]==6 && $tmp1[2]<7)?$tmp1[0]:$tmp1[0]+1;//判断高考是在今年还是下一年
$day="{$Y}-6-7 0:0:0";//下一次高考的时间
$tmp=comDate($today,$day);
$con="{$tmp[0]}天 {$tmp[1]}小时 {$tmp[2]}分钟 {$tmp[3]}秒";//构造结果字符串
echo "<p>现在是:{$today}</p>";
if(($tmp1[1]==6) && ($tmp1[2]==7 || $tmp1[2]==8 || $tmp1[2]==9))
{
echo "<p>高考期间,好好复习备考</p>";
}
else{
echo "<p>离高考还有 {$con} </p>";
}
echo '<p>'.mingYan().'</p>';//显示名言警句



function comDate($date1,$date2)
{//计算两个日期相隔时间的函数,返回结果为数组
$tmp1=explode(' ',$date1);
$tmp2=explode(' ',$date2);
$d_1=explode('-',$tmp1[0]);//保存年月日的数组
$d_2=explode('-',$tmp2[0]);
$t_1=explode(':',$tmp1[1]);//保存时分秒的数组
$t_2=explode(':',$tmp2[1]);
$d1=mktime($t_1[0],$t_1[1],$t_1[2],$d_1[1],$d_1[2],$d_1[0]);//把日期变成秒数
$d2=mktime($t_2[0],$t_2[1],$t_2[2],$d_2[1],$d_2[2],$d_2[0]);
$d3=$d2-$d1;//两日期间相差的秒数
$seconds=$d3%60;
$minutes=floor($d3%(60*60)/60);
$hours=floor($d3%(60*60*24)/(60*60));
$days=floor($d3/(60*60*24));

return array($days,$hours,$minutes,$seconds);
}


function mingYan()//返回底部显示的名言
{
$tmp=array(
"一寸光阴一寸金呀,还不珍惜每一天吗?",
"光阴好比河中水,只能流去不能回",
);
$n=count($tmp);
return $tmp[rand(0,$n-1)];
}

?>


</html>
演示
«Newer      Older»
Comment:
Name:

Back to home

Subscribe | Register | Login | N