I am building a clock using Flash/Actionscript to display multiple time zones, offset against UTC and adjusting for Daylight Saving for the timezones that adhere to it. My problem is that one of the time zones is Mumbai, which is 5.5 hours ahead of UTC, and which incidentally doesn't adhere to DST.
Here's some code;
time=new Date(); // time object
//set the time
var seconds = time.getUTCSeconds()
var minutes = time.getUTCMinutes()
var hours = time.getUTCHours()
//set the date
var day = time.getUTCDate()
var month = time.getUTCMonth()
var year = time.getUTCFullYear()
var dst;
//sets the daylight saving rule
if((day>=13 && month>=3) && (day<=6 && month<=11)){
dst = true;
}
//Adds zeros to single figures
if(minutes<10)
{
minutes = "0" + minutes;
}
if(seconds<10)
{
seconds = "0" + seconds;
}
Hopefully that explains the background, now what happens is I output the time to a dynamic text box like this;
if (hours<19){
mumbai.text = (hours +5.5) + ":" + minutes + ":" + seconds;
}
else{
mumbai.text = (hours -19) + ":" + minutes + ":" + seconds;
}
Now, this is obviously wrong as my clock outputs something like 18.5:00:00 instead of 18:30:00, am I making sense?
My first solution would be to add 30 to the minute count;
mumbai.text = (hours +5) + ":" + (minutes + 30) + ":" + seconds;
but this obviously adds 30 minutes to the minutes all the time, and doesn't add an hour when the minutes are greater than 30.
I would appreciate some advice, I know the answer is probably staring me in the face, but I can't see it!!!
Thanks in advance!
Colin

New Topic/Question
Reply


MultiQuote



|