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

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 English version
Recommended: Win version, supports code prompts!

Atom editor mac version download
The most popular open source editor

Notepad++7.3.1
Easy-to-use and free code editor

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
