当前位置:首页 »“秋了秋”个人博客 » 网络技术 » php输出各种时间代码表示

php输出各种时间代码表示

作者:秋了秋 发表时间:2014年11月15日

为了交换友情链接的公平性,我在“秋叶网络博客”的留言板上写上交换条件,我都是写的建站时间。之前是手动更新时间的,每隔几个月我就把留言板的网页文件下载下来,把数字更换一下,为了解决这等麻烦事,所以懒人自有懒招。弄了个动态时间显示,通过php计算从某个时间点到现在时刻的时间差,从而每时每刻自动更新,我也就可以去睡大觉了。。

因为这等事,把php输出时间代码学习了一遍,现在来按照我的思维理顺一下:

php时间差的计算: <?php $begintime=strtotime("2014-01-27");//起始时间 $nowtime=strtotime("now");//获取现在的时间 print_r (floor(($nowtime-$begintime)/(3600*24)/30));//时间差计算,加减乘除运算,这里输出的是月份,要输出天数,去掉/30,以此类推,小学数学学过吧。 ?>

php输出当前具体时间: <?php echo date('Y.m.d',time()); ?>//输出时间格式为2014.11.15年月日,见“秋叶网络博客”首页页脚处。 <?php echo date("Y-m-d ",strtotime(" -1 day"));?>//昨天 <?php echo date("Y-m-d ",strtotime(" -1 day"));?>//明天 <?php echo date("Y年m月d日 l H:i:s A"); ?>//输出格式:2014年08月29日 Monday 04:52:25 AM <?php echo date("y-n-j D h:i:s a"); ?>//输出格式:14-8-29 Mon 04:52:25 am <?php echo date("Y年n月j日 l G:i:s a",strtotime("now"));?>//输出格式:2014年8月29日 Monday 7:56:05 am

php倒计时时间计算: <?php $time1=strtotime("2015-11-15 16:33:00"); $time2=strtotime("now"); $sec=$time1-$time2; $year=floor($sec/3600/24/365);//年 $temp=$sec-$year*365*24*3600; $month=floor($temp/3600/24/30);//月 $temp=$temp-$month*30*24*3600; $day=floor($temp/3600/24);//日 $temp=$temp-$day*3600*24; $hour=floor($temp/3600);//小时 $temp=$temp-$hour*3600; $minute=floor($temp/60);//分 $second=$temp-$minute*60;//秒 $nimei="距离儿童节还有".$year."年".$month."月".$day."天".$hour."小时".$minute."分".$second."秒"; if ("$year"=="0"){$nimei="距离儿童节还有".$month."月".$day."天".$hour."小时".$minute."分".$second."秒";} elseif("$month"=="0"){$nimei="距离儿童节还有".$year."年".$day."天".$hour."小时".$minute."分".$second."秒";} elseif("$day"=="0"){$nimei="距离儿童节还有".$year."年".$month."月".$hour."小时".$minute."分".$second."秒";} elseif("$hour"=="0"){$nimei="距离儿童节还有".$year."年".$month."月".$day."天".$minute."分".$second."秒";} elseif("$minute"=="0"){$nimei="距离儿童节还有".$year."年".$month."月".$day."天".$hour."小时".$second."秒";} elseif("$second"=="0"){$nimei="距离儿童节还有".$year."年".$month."月".$day."天".$hour."小时".$minute."分";} echo $nimei;//输出格式:距离儿童节还有1年6月18天15小时49分11秒 ?>

0
文章作者: “秋了秋”个人博客,本站鼓励原创。
转载请注明本文地址:http://netblog.cn/blog/172.html
目录: 网络技术标签: PHP输出时间 11779次阅读

请求播放音乐,请点击播放

登 录
点击获取验证码
还没账号?点击这里