Emlog给自己博客加个节日倒计时
百度找到的网钛写的节日倒计时代码
咱们em只需要把OT_NongLiGongLi.php放到模板目录下然后
在想出现的地方插入
也就是jieri.php里面的文件
<?php
/*
##########################################################
名称:节日倒计时 V1.0
作者:网钛工作室
日期:2010-09-23
网址:http://www.oneti.cn/
邮箱:877873666@qq.com
版权:可自由传播,也可修改后应用到自己程序里,但请保留该版权及注释信息
##########################################################
*/
header("Content-Type: text/html; charset=UTF-8");
// 防止 PHP 5.1.x 使用时间函数报错
if(function_exists('date_default_timezone_set')) {
@date_default_timezone_set('PRC'); //PRC是中华人民共和国时区
}
require_once View::getView('OT_NongLiGongLi');
function OT_WeekNum($num){
if ($num==0){ $num=7; }
return $num;
}
$nongGong = new OT_NongLiGongLi();
$jieriArr = array();
$nowYear = date("Y");
$nowDate = date("Y-m-d");
// 公历节日
$jieriArr[] = array($nowYear ."-1-1", "元旦");
$jieriArr[] = array($nowYear ."-2-14", "情人节");
$jieriArr[] = array($nowYear ."-3-8", "妇女节");
$jieriArr[] = array($nowYear ."-3-12", "植树节");
$jieriArr[] = array($nowYear ."-4-1", "愚人节");
$jieriArr[] = array($nowYear ."-4-5", "清明节");
$jieriArr[] = array($nowYear ."-5-1", "劳动节");
$jieriArr[] = array($nowYear ."-5-". (15 - date("w",strtotime($nowYear ."-5-1"))), "母亲节");
$jieriArr[] = array($nowYear ."-6-1", "儿童节");
$jieriArr[] = array($nowYear ."-6-". (22 - date("w",strtotime($nowYear ."-6-1"))), "父亲节");
$jieriArr[] = array($nowYear ."-9-10", "教师节");
$jieriArr[] = array($nowYear ."-10-1", "国庆节");
$jieriArr[] = array($nowYear ."-11-11", "光棍节");
$jieriArr[] = array($nowYear ."-11-". (26 - date("w",strtotime($nowYear ."-11-1"))),"感恩节");
$jieriArr[] = array($nowYear ."-12-24", "平安夜");
$jieriArr[] = array($nowYear ."-12-25", "圣诞节");
// 农历节日
$jieriArr[] = array($nongGong->NongToGong(($nowYear-1) ."-12-24"), "小年(南方)");
$jieriArr[] = array($nongGong->NongToGong(($nowYear-1) ."-12-8"), "腊八节");
$jieriArr[] = array($nongGong->NongToGong(($nowYear-1) ."-12-23"), "小年(北方)");
//$jieriArr[] = array($nongGong->NongToGong(($nowYear-1) ."-12-24"),"小年(南方)");
$jieriArr[] = array($nongGong->NongToGong(($nowYear-1) ."-12-30"), "除夕");
$jieriArr[] = array($nongGong->NongToGong($nowYear ."-1-1"), "春节");
$jieriArr[] = array($nongGong->NongToGong($nowYear ."-1-15"), "元宵节");
$jieriArr[] = array($nongGong->NongToGong($nowYear ."-5-5"), "端午节");
$jieriArr[] = array($nongGong->NongToGong($nowYear ."-7-7"), "七夕情人节");
$jieriArr[] = array($nongGong->NongToGong($nowYear ."-8-15"), "中秋节");
$jieriArr[] = array($nongGong->NongToGong($nowYear ."-9-9"), "重阳节");
/*
$jieriArr[] = array($nowYear ."-9-18", "中国国耻日");
$jieriArr[] = array($nowYear ."-7-1", "中共建党节");
$jieriArr[] = array($nowYear ."-7-7", "抗日战争纪念日");
$jieriArr[] = array($nowYear ."-8-1", "建军节");
$jieriArr[] = array($nowYear ."-9-3", "抗日战争胜利纪念日");
$jieriArr[] = array($nowYear ."-11-7", "十月革命纪念日");
$jieriArr[] = array($nowYear ."-12-13", "南京大屠杀纪念日");
$jieriArr[] = array($nowYear ."-12-20", "澳门回归纪念日");
*/
// 判断是否是闰年
if ($nowYear % 400 == 0 || ($nowYear % 4 == 0 && $nowYear % 100 != 0) ){
$JRdiff=366;
}else{
$JRdiff=365;
}
foreach ($jieriArr as $value){
if ($JRdiff==0){ break; }
$nowDiff = $nongGong->DateDiffDay2($nowDate,$value[0]);
if ($nowDiff>=0){
if ($nowDiff<$JRdiff){
$JRdiff = $nowDiff;
if ($JRdiff==0){
$JRstr2="";
}else{
$JRstr2="离". $JRdiff ."天";
}
$JRstr=$JRstr2 ."到『". $value[1] ."』";
}
}
}
if ($JRdiff<0){
$JRstr="离". $nongGong->DateDiffDay2($nowDate,($nowYear+1) ."-1-1") ."天"."『元旦』";
}
echo($JRstr);
?>
发表评论