I’ve got a variable that holds a number of miliseconds which represents the timespan from now to a specified point in the future.
I want to convert this milisecond figure into a timespan value I can display to users.
I know I can do this the naive way with modulo arithmetic and manually displaying the result to the user, but I want to do this using the Date() API built-in to Javascript/ECMAScript.
This is how I generate it:
var timespanInMS = timeInFuture.getTime() - now.getTime();
var diff = new Date( timespanInMS );
alert( "Hours: " + diff.getHours() + " Minutes: " + diff.getMinutes() );
However this only works when the user’s computer is in the UTC timezone. If they’re in Pacific (UTC-8) then the value of ‘diff’ is off by 16 hours (even though the timespanInMS figure is the same).
Thanks
Perhaps
getUTCHoursandgetUTCMinutesmight work? See https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Date for more information.