Last active
June 24, 2017 14:43
-
-
Save bih/62f4b847b5ec100f61677eaa22c9f82c to your computer and use it in GitHub Desktop.
Calculate Your Age
This file contains hidden or 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
(function(date_of_birth, decimal_points){ | |
var date_today = Date.now() | |
, date_born = Date.parse(date_of_birth) | |
, difference = date_today - date_born; | |
var divided_to_seconds = difference / 1000 | |
, divided_to_minutes = divided_to_seconds / 60 | |
, divided_to_hours = divided_to_minutes / 60 | |
, divided_to_days = divided_to_hours / 24 | |
, divided_to_years = divided_to_days / 365; | |
var decimal_divisor = 10 ** decimal_points; | |
return parseInt(divided_to_years * decimal_divisor) / decimal_divisor; | |
})('1993-01-01', 10); |
This file contains hidden or 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
d='1993-01-01',l=10;parseInt((Date.now()-Date.parse(d))/31536000000*(10**l))/(10**l) |
This file contains hidden or 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
d=Date;((d.now()-d.parse('1993-01-01'))/31536000000).toFixed(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment