Calculate How long you have lived (in seconds or years) in Ruby

This program will helps you to find the number of years and seconds that you have lived in this Planet.

Source code :

time = Time.now

yearOfBirth = 1995 # Change your year of birth here

# Finding the current year

currentYear = time.year

# Calculating the number of years you've lived

livedYears = currentYear - yearOfBirth;

puts "You have lived " + livedYears.to_s + " years in this Planet !"

# Calculating the number of seconds you've lived

livedSeconds = yearOfBirth * 60 * 60 * 24 * 365

puts "which is equal to " + livedSeconds.to_s + " seconds."

Output :

You have lived 21 years in this Planet !
which is equal to 62914320000 seconds.

Notes :

Change the yearOfBirth variable to your birth year and run the program


Output :


                

Comments :