Home > Backend Development > PHP Tutorial > 分享一下贝贝成长进度的php代码_PHP

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

WBOY
Release: 2016-06-01 12:10:22
Original
883 people have browsed it

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template