Hoping one of you programming geniouses could help me on this. I created a countdown timer which needs to countdown an event accurately no matter where you are located in the world. So based on my understanding of timezones etc.. and flash the only way I can get Paris time if I am not in Paris is by using my machine clock to get a time offset between that and Paris. But this isn't working as I expect it and im totally confused:S
I would think that if an event is happening say in 5 hours, that no matter what time or timezone I have on my machine my countdown should still say the event is due in 5 hours. But if I change my timezone or time my countdown also changes which to me doesn't make sense although I could be wrong??? My code is below could anybody help me out? Maybe my logic is off?? Could anyone help?
ActionScript Code:
var _endDate:Date = new Date(2010,1,13);
//This is 1 because Paris is one hour ahead of UTC
var timeZoneFromUTC:Number = 1;
countdownTimer=new Timer(10);
countdownTimer.addEventListener(TimerEvent.TIMER,_updateTime);
countdownTimer.start();
function _updateTime(e:TimerEvent){
_now = new Date();
//Converting our desired timezone difference from hours to minutes
var $timeZoneFromUTCMinutes:Number = timeZoneFromUTC * 60;
//Converting timezone offset and timezone from UTC minutes into seconds. Then adding them together
//This is the total offset (in seconds) from your current location to the desired location.
var $secondsOffset:Number = (_now.getTimezoneOffset() * 60) + ($timeZoneFromUTCMinutes * 60)
//Converting offset from seconds to milliseconds to feed to the formula below
var $milliSecsOffset:Number = $secondsOffset * 1000;
_timeLeft =(_endDate.getTime() - _now.getTime()) + -($milliSecsOffset);
_seconds = Math.floor(_timeLeft / 1000);
_minutes = Math.floor(_seconds / 60 );
_hours = Math.floor(_minutes / 60);
_days = Math.floor(_hours / 24);
_seconds %= 60;
_minutes %= 60;
_hours %= 24
trace (_days)
trace (_hours)
trace(_minutes)
trace (_seconds)
if(_days==0 && _hours==0 && _minutes==0 && _seconds==0){
dispatchEvent(new Event("timeUp"));
countdownTimer.stop();
trace ("times up!!!")
}else dispatchEvent(new Event("active"));
}