How can I translate this pseudo code into working JS [don’t worry about where the end date comes from except that it’s a valid JavaScript date].
var myEndDateTime = somedate; //somedate is a valid JS date var durationInMinutes = 100; //this can be any number of minutes from 1-7200 (5 days) //this is the calculation I don't know how to do var myStartDate = somedate - durationInMinutes; alert("The event will start on " + myStartDate.toDateString() + " at " + myStartDate.toTimeString());
Once you know this:
Dateby calling the constructor with milliseconds since Jan 1, 1970.valueOf()aDateis the number of milliseconds since Jan 1, 197060,000milliseconds in a minute :-]In the code below, a new
Dateis created by subtracting the appropriate number of milliseconds frommyEndDateTime: