Created
February 16, 2014 13:39
-
-
Save Ank13/9034360 to your computer and use it in GitHub Desktop.
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
puts "What year were your born?" | |
birth_year = gets.chomp | |
puts "What month were your born?" | |
birth_month = gets.chomp | |
puts "What day were your born?" | |
birth_day = gets.chomp | |
seconds_diff = Time.now - Time.new(birth_year, birth_month, birth_day) | |
pretty_print_seconds = seconds_diff.round(0).to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse | |
puts "You are #{pretty_print_seconds} seconds old." | |
years = seconds_diff / 60 / 60 / 24 / 365 | |
puts "You are #{years.round(2)} years old." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment