·您当前的位置:首页 > 技术教程 > PHP教程 >

[php]php日期记时记录孩子的成长

时间:2017-01-04 14:56酷播
[php]php日期记时记录孩子的成长

[php]php日期记时记录孩子的成长

  1. <? 
  2. date_default_timezone_set('Asia/Shanghai'); 
  3. //以上一句为设置时区,其实不设也行,但是zde debug的时候会有提示,说什么不安全的函数…添上吧。 
  4.  
  5. echo date('Y-m-d H:i:s').' 今天是'.date('Y').'年的第'.date('W').'周'; 
  6.  
  7. $stime='2005-11-03 10:08'; 
  8. echo "<br/><br/>***自出生(<font color=blue>$stime</font>)以来…:<br/><br/>"; 
  9. echo "今天是第<font color=red><b>".Lnbsp(daysofnow($stime),3)."</b></font>天<br/>"; 
  10. echo "今天是第<font color=red><b>".Lnbsp(weeksofnow($stime),3)."</b></font>周<br/>"; 
  11. echo "今天是第<font color=red><b>".Lnbsp(monthsofnow($stime),3)."</b></font>个月<br/>"; 
  12. echo "今天是第<font color=red><b>".Lnbsp(yearsofnow($stime),3)."</b></font>年<br/>"; 
  13. /* 
  14. $output=sprintf(" 今天是第<font color=red><b>%03d</b></font>天<br/>今天是第< font color=red><b>%03d</b></font>周<br/>今天是第< font color=red><b>%03d</b></font>个月<br/>今天是第< font color=red><b>%03d</b></font>年<br/& gt;",daysofnow($stime),weeksofnow($stime),monthsofnow($stime),yearsofnow($stime)); 
  15. echo $output; 
  16. */ 
  17.  
  18. function weeksofnow($stime) 
  19. { 
  20.     $ftime=strtotime($stime); 
  21.     $fweeks=date('w',$ftime); 
  22.     if ($fweeks==0) $fweeks=7; 
  23.     $nweeks=date('w'); 
  24.     if ($nweeks==0) $nweeks=7; 
  25.     $ftemp=strtotime(date('Y-m-d 00:00:00',$ftime))-$fweeks*60*60*24; 
  26.     $ntemp=strtotime(date('Y-m-d 00:00:00',time()))+(7-$nweeks)*60*60*24; 
  27.     //echo date('w',$ftemp)."<br/>....<br/>".date('w',$ntemp)."<br/>"; 
  28.     return ($ntemp-$ftemp)/60/60/24/7; 
  29. } 
  30.  
  31. function daysofnow($stime) 
  32. { 
  33.     $ftime=strtotime($stime); 
  34.     return ceil(abs((time()-$ftime)/(60*60*24))); 
  35. } 
  36.  
  37. function monthsofnow($stime) 
  38. { 
  39.     $ftime=strtotime($stime); 
  40.     $fmonth=date('m',$ftime); 
  41.     $fyear=date('Y',$ftime); 
  42.     $nmonth=date('m'); 
  43.     $nyear=date('Y'); 
  44.     $result=($nyear-$fyear)*12+$nmonth-$fmonth+1; 
  45.     return $result; 
  46. } 
  47.  
  48. function yearsofnow($stime) 
  49. { 
  50.     $ftime=strtotime($stime); 
  51.     $fyear=date('Y',$ftime); 
  52.     $nyear=date('Y'); 
  53.     return $nyear-$fyear+1; 
  54. } 
  55.  
  56. // 下面的函数只是加空格用的,不是核心内容,只为美观 
  57. function Lnbsp($data,$num) 
  58. { 
  59.     $result=trim($data); 
  60.     for($i=$num;$i>=strlen($data);$i--) { 
  61.         $result='&nbsp;'.$result; 
  62.     } 
  63.     return $result; 
  64. } 
  65. ?> 

来源:http://www.9958.pw/post/php_date_time_summary

热门文章推荐

请稍候...

保利威视云平台-轻松实现点播直播视频应用

酷播云数据统计分析跨平台播放器