Created
March 5, 2013 10:00
-
-
Save satoshin2071/5089209 to your computer and use it in GitHub Desktop.
rubyで生年月日から年齢を抽出する。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
#現在の日時 | |
now_date = Time.now | |
#誕生日 | |
birth_date = Time.parse(1972,8,10) | |
#現在の日時と誕生日の差分を出し、年数に換算し、さらにフォーマット関数で年だけを表示 | |
my_age = sprintf("%d",((now_date - birth_date) / 60 / 60 / 24)/365) | |
p my_age | |
## 実行結果 | |
34 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment