Home >php教程 >php手册 >分享一下贝贝成长进度的php代码

分享一下贝贝成长进度的php代码

WBOY
WBOYOriginal
2016-06-13 11:57:52927browse

主要功能是根据贝贝的出生日期来显示贝贝现在多大了,实时显示贝贝的成长。
用当前时间减去出生的日期,但是可以显示出来几岁,几个月,和几天。
天的算法有点问题,没有考虑到大小月和2月份。

复制代码 代码如下:


function getDays() {
putenv("TZ=Asia/Chongqing");
$by = 2006;
$bm = 7;
$bd = 7;
$rday="";

$today = getdate();
$by = $today[year] - $by;
$bm = $today[mon] - $bm;
$bd = $today[mday] - $bd;
if ($bd $bd = 30 + $bd;
$bm--;
}
if ($bm $bm = 12 + $bm;
$by--;
}
#print $by."-".$bm."-".$bd;
if ($by > 0) {
$rday = $by . "岁";
}
if ($bm == 0&&$bd == 0){
$rday .="生日";
}else{
if ($bm == 0){
$rday.="零".$bd."天";
}elseif ($bd == 0){
$rday.=$bm."个月整";
}else{
$rday.=$bm."个月".$bd."天";
}
}
return $rday;
}


用的时候直接

复制代码 代码如下:




就可以了
空下来再完善以下,再写一个js的版本。
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn