The popular comic xkcd posed this equation for converting time complete into a date:
I've been trying to do the same in JavaScript, although I keep getting -Infinity
. Here's the code:
var p = 5; // Percent Complete
var today = new Date();
today = today.getTime();
var t;
t = (today) - (Math.pow(Math.E, (20.3444 * Math.pow(p,3))) -
Math.pow(Math.E,3));
document.write(t + " years");
Time will return a huge number (milliseconds), and I know that the equation isn't meant to deal with milliseconds - so how would one do an advanced date equation with JavaScript?
You've made 3 mistakes:
p
should be a decimal between 0 and 1 to indicate the ratio of progress completed.T = (current date) - (a number in years)
T = (current date - a number) in years
(e^…-e^3)
and then subtract that many years from t
+3
which was in the original formulaEDIT:
Here's some working code as a JSFiddle, although Javascript runs out of dates at around 75% completed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With