天计算一个人一直活在他的第N个生日的号码吗? (闰年的挑战)他的、闰年、号码、生日

由网友(仅一心 °)分享简介:可能重复: How我可以计算一个人在一年的年龄,月,日? 如何计算天数的人一直活在他的第N个生日?考虑到他的出生月,日,年,和他的年龄?如何解决闰年的挑战?How to calculate the number of days that person has been alive on his Nth birth...

可能重复:   How我可以计算一个人在一年的年龄,月,日?

如何计算天数的人一直活在他的第N个生日?考虑到他的出生月,日,年,和他的年龄?如何解决闰年的挑战?

How to calculate the number of days that person has been alive on his Nth birthday? given his birth month, day, year, and his age? How to solve the leap year challenge?

推荐答案

下面是一个(形式的)一行程序在Perl:

Here's a (sort of a) one-liner in Perl:

$ perl -MPOSIX -e '($d, $m, $y, $a) = @ARGV; print ((mktime(0,0,0,$d,$m+1,$y+$a-1900) - mktime(0,0,0,$d,$m+1,$y-1900)) / 86400)' 23 4 1975 29
10593

当然,这个假冒的关键闰年计算到 POSIX :: mktime 的功能。

阅读全文

相关推荐

最新文章