我正在处理涉及日期的任务.我有一个人的月龄+天.现在我想知道这个人达到几个月的特定年龄的日期.
例如:
A person is 250 months and 15 days old on 2010-1-25.
On which date this person will become 300 months old?
Run Code Online (Sandbox Code Playgroud)
功能签名可能是:
function getReqDate( $startDate, $currAgeMonths, $currAgeDays, $reqAgeMonths ) {
//return date
}
Run Code Online (Sandbox Code Playgroud)
由于您从出生日期计算当前年龄,我建议您使用生日而不是当前年龄来计算用户何时获得300个月大.以下是上面给出的DateTime解决方案的等价物(不需要5.3):
echo date('r', strtotime('+300 months', strtotime('1990-10-13')));
Run Code Online (Sandbox Code Playgroud)
第二个参数是上面给出的生日时间戳
Tue, 13 Oct 2015 00:00:00 +0200
Run Code Online (Sandbox Code Playgroud)
进一步阅读:
| 归档时间: |
|
| 查看次数: |
193 次 |
| 最近记录: |