"Back in Time" xkcd

The popular xkcd comic put this equation for converting time to date:

Backward in time

I am trying to do the same in JavaScript, although I keep getting -Infinity. Here is 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 amount (milliseconds), and I know that the equation is not designed to work with milliseconds - so how could you use the advanced date equation with JavaScript?

+5
source share
2 answers

You made 3 mistakes:

  • p must be a decimal number from 0 to 1 to indicate the ratio of progress made.
  • Result:
    T = (current date) - (a number in years)
    no
    T = (current date - a number) in years
    , you must first calculate (e^…-e^3), and then subtract that from many yearst
  • +3,

EDIT:

JSFiddle, Javascript 75%

+2

var p = 5; // Percent Complete 

fraction complete, 0.05 5%. p 1 .

p = 5 5% ()

exp(20.3444*10^6)

, double, exp(40) exp(1000) double.

+2

All Articles