CountDown Timer and Time Zones

I found your absolutely wonderful tutorial section and between the basics and the fully working CountDown timer that you had there, I have been able to make my first Flash movie (or is it an application???).

The basic premise is that I want to capture the server time (to try to eliminate any errors on the users clock plus all the EST, EDT, PDT, etc. :slight_smile:

So, I found the way to get the server time which was in a modified version of the tutorial file:


/*+----------------------------------------------------------------------------------------+
| Make a new loadVars object to get the server date and then check for loading success. |
| If it's okay, we assign countdown to run every frame for counter and show the counter |
| clip since it was hidden before the countdown.										 |
+----------------------------------------------------------------------------------------+*/
server = new LoadVars();
server.onLoad = function(ok)
{
if (!ok) return trace("Server error! Unable to obtain date from server");
// counter.onEnterFrame = countdown;
// counter._visible = true;
//
/*+----------------------------------------------------------------------------------------+
| Offset the recieved server time by the current value of getTimer since getTimer starts |
| at 0 when the movie starts. By the time the server time loads, getTimer will be some |
| higher value. This accounts for the extra time added on from getTimer in countdown	 |
| every frame. Plus, since time() in php returns seconds and not milliseconds (which is |
| used here) *1000 is added to increase its value to represent milliseconds.			 |
+----------------------------------------------------------------------------------------+*/
// this.time = "1129420069";
this.time = Number(this.time)*1000 - getTimer();
};
/*+----------------------------------------------------------------------------------------+
| Load in the time from a php file (or any other server-side resource). The value we want|
| from the server is the milliseconds representation of the current time as the server |
| sees it.																			 |
+----------------------------------------------------------------------------------------+*/
server.load("flash/gettime.php");
/* gettime.php:
<?php
echo "time=" . time();
?>
*/

I ran it through in debug and all is working great on that side and I verified the actual time zone and time being returned from the server by echo-ing back to the screen during another php execution.

The next thing is to figure out what we are conting down to. That’s the eventtime and I read that in from an xml file.


function loadXML(loaded)
{
if (loaded)
{
	_root.tmpEventDate = this.childNodes[0].childNodes[0].childNodes[0].nodeValue;
// Date format in XML file = mm/dd/yyyy-hh:mm:ss
// Date([yearOrTimevalue:Number], [month:Number], [date:Number], [hour:Number], [minute:Number], [second:Number], [millisecond:Number])
tmpYear = number(tmpEventDate.substr(6, 4));
tmpMonth = number(tmpEventDate.substr(0, 2));
tmpDay = number(tmpEventDate.substr(3, 2));
tmpHour = number(tmpEventDate.substr(11, 2));
tmpMin = number(tmpEventDate.substr(14, 2));
tmpSec = number(tmpEventDate.substr(17, 2));
xmlEventDate = new Date(tmpYear, tmpMonth-1, tmpDay, tmpHour, tmpMin, tmpSec, 0);
xmlEventMillisecs = xmlEventDate.getTime();
eventMillisecs = xmlEventMillisecs;
counter.onEnterFrame = countdown;
	counter._visible = true;
//	_root.comments = this.firstChild.childNodes[1].nodeValue;
//	name_txt.text = _root.inventor;
//	comment_txt.text = _root.comments;
}
else
{
	trace("file not loaded!");
}
};
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("flash/TMB_CountDown.xml");

That works great too. I use a normal format in the xml file so that anyone can edit it easier and handle all the conversion in here. When I finally end up with eventMillisecs, I should have a number that I can subtract the current time from and get a time difference right?


var currentMillisecs = server.time + getTimer();
this.msecs = eventMillisecs - currentMillisecs;

No problem. All is working great. I’m thinking that if the server is in ET and the eventTime is entered relative to ET, then the time difference should be an absolute value and should not care what time zone the user (viewer of the site in this case) is located in right? After all, the server is providing the server.time and the xml file is providing the eventTime so the user’s settings should not come in to play.

But they are and I can’t quite figure out why. I’ve searched here on countdown, timer, gmt, etc and read almost all of the posts but noone seems to have had this question/problem.

Thanks for taking the time to read this and hope you can help!