PDA

View Full Version : Display Date and Time in a certain country



blackjersey
March 2nd, 2005, 07:55 AM
Hi guys!

By default, when you visit a website that is made entirely in Flash and there is a Tme and Date movie clip feature... you know... it gets the current time and date of your computer so you're actually seeing your own time, right?

What I've always wanted to do is when you visit a website that is made entirely in Falsh, and you have a Time and Date movie clip that tells the creators current time and the current date instead of just getting the values of your computer time and displaying your own. I'm in the Philippines so I want the visitors of my site to view what time and date is it in the Philippines.

Can it be done?

Xeef
March 2nd, 2005, 08:55 AM
var today_date:Date = new Date();
// LOCAL time
trace(today_date.getHours());
// Greanwich (or how ever you splet it) Time
trace(today_date.getUTCHours());
// this line Will show on any computer the time i have here :)
IBIZATimeZone = +1;
trace(today_date.getUTCHours()+IBIZATimeZone);

e.s.x.s
March 2nd, 2005, 09:06 AM
yes it can be...
u can use
my_date.getTimezoneOffset(); to get the user's timezone and than show the Philippines' local time according to the timezone differences.

e.s.x.s
March 2nd, 2005, 09:07 AM
yes it can be...
u can use

my_date.getTimezoneOffset();

to get the user's timezone and than show the Philippines' local time according to the timezone differences.

Xeef
March 2nd, 2005, 09:20 AM
@e.s.x.s :D that what i was looking for in the first and din't find it :p

but now that i look to it is my one beter ! :p

blackjersey
March 2nd, 2005, 09:26 AM
Wow... thanks guys! Btw, I can understand action scripts but I think I will be lost after doing my_date.getTimezoneOffset();

Can you give me a sample code after the code above to show the time in the Philioppines?

Sorry I just need your help badly... I'm creating a website to show what I'm actually doing in certain point in time. For example:

If the time in the Philippines is: 09:45 p.m. then I will have a dynamic text box displaying "blackjersey is still sleeping" or if the time in the Philippines is 07:00 a.m. It will display "blackjersey is at work" .... hehe sorry if I'm asking too much ; )


Thanks again!

Xeef
March 2nd, 2005, 10:14 AM
use my code and change

IBIZATimeZone = +1;
to what ever time you have
eg
IBIZATimeZone = -5; or what ever ofset you have there

e.s.x.s
March 2nd, 2005, 10:29 AM
var my_date = new Date();
time = my_date.getHours(); // gives 17
minuteDifference = my_date.getTimezoneOffset(); // gives -120
hourDifference = minuteDifference/60; // gives -2
myDiff = 5; // GMT +5;
exactDiff = myDiff + hourDifference; // gives 3
myTime = time + exactDiff; // gives 20

this was the long way which u can see the difference of the tiimezone as minutes.


var my_date = new Date();
GMT = my_date.getUTCHours(); // gives 15
myDiff = 5; // GMT +5;
myTime = GMT + myDiff; // gives 20

this is the short way ;)

Xeef
March 2nd, 2005, 10:42 AM
@e.s.x.s
whaHahaha :D the AS tag GET's you !!!!

http://www.actionscript.org/forums/showthread.php3?t=65875&page=2

e.s.x.s
March 2nd, 2005, 10:49 AM
:D i forgot that AS tag isn't supprot Actionscript 2.0 :)

Xeef
March 2nd, 2005, 10:53 AM
it do suport it

the only problem are the smiles

var a:Date =new Date

var a:Date =new Date

var a:Date =new Date

e.s.x.s
March 2nd, 2005, 11:29 AM
:) i knew that it was about the smillies.. but thank u for explaining the problem ;)

asteriks
October 24th, 2006, 10:16 AM
i need to display time of hongkong ... and i am using this code to display time right now , it basically shows time from the pc you are @. i am really a beginer in actionscript so it would be great if someone could help me out and tell me wat changes should i make in the actionscript. thank you


function howlong(arg) {
if (length(arg)==1) {
arg = "0" + arg;
return arg;
}
else {
arg = arg;
return arg;
}
}
myDate = new Date();

hr = howlong(String(myDate.getHours()));
mnt = howlong(String(myDate.getMinutes()));

daytext = myDate.getDay();
dd = myDate.getDate();
mm = myDate.getMonth();
yyyy = myDate.getFullYear();

switch (daytext) {
case 0: daytext = "Sunday";
break;
case 1: daytext = "Monday";
break;
case 2: daytext = "Tuesday";
break;
case 3: daytext = "Wednesday";
break;
case 4: daytext = "Thursday";
break
case 5: daytext = "Friday";
break;
case 6: daytext = "Saturday";
break
}

switch (mm) {
case 0: mm = "January";
break;
case 1: mm = "February";
break;
case 2: mm = "March";
break;
case 3: mm = "April";
break;
case 4: mm = "May";
break
case 5: mm = "June";
break;
case 6: mm = "July";
break
case 7: mm = "August";
break
case 8: mm = "September";
break
case 9: mm = "October";
break
case 10: mm = "November";
break
case 11: mm = "December";
break
}


textdate = (hr + ":" + mnt + " - " + daytext + "," + dd + " " + mm + " " + yyyy)

asteriks
October 26th, 2006, 07:33 PM
i am still looking for solution quick as possible :(

glosrfc
October 27th, 2006, 07:32 PM
To show the time in a specific timezone you need to do three things:
1. Always work according to Greenwich Mean Time or UTC by using Date.getTime
2. Add on the users local timezone offset using Date.getTimezoneOffset
3. Add on the remote location timezone offset.

So Hong Kong time for a user in London at midnight, GMT would be midnight + 0 hrs timezone offset + 8 hrs HK timezone offset.
For a user in New York it would be GMT midnight + 5 hrs timezone offset + 8 hrs HK timezone offset.
A user in Berlin would be GMT midnight + -1 hour timezone offset + 8 hrs HK timezone offset.

Note that Flash automatically reverses the timezone information so New York, which is five hours behind GMT, becomes plus 300 minutes while Berlin, one hour ahead of GMT, becomes - 60 minutes.

This F8 example should work for you:

// Get the value of the current time in milliseconds since midnight on January 1, 1970
var GMT:Number = new Date().getTime();
// Adjust for the timezone difference of the country of origin
var GMTtimeDifference:Number = 8; // Expressed in hours, using Hong Kong as an example
// Convert the timezone difference into milliseconds
GMTtimeDifference = GMTtimeDifference * 60 * 60 * 1000;
// Get the local timezone difference
var localtimeDifference:Number = new Date().getTimezoneOffset();
trace (localtimeDifference);
// Convert the local timezone difference into milliseconds
localtimeDifference = localtimeDifference * 60 * 1000;
// Add both timezone differences to the date value and return this as a date
var myTime:Date = new Date(GMT + GMTtimeDifference + localtimeDifference);
// Extract date and time values from country of origin date
var hr:String = howlong(String(myTime.getHours()));
var mnt:String = howlong(String(myTime.getMinutes()));
var daytext:String = getDayofWeekAsString(myTime.getDay());
var dd:Number = myTime.getDate();
var mm:String = getMonthAsString(myTime.getMonth());
var yyyy:Number = myTime.getFullYear();
// Get the local time
var localTime:Date = new Date();
// Extract date and time values from local date
var localhr:String = howlong(String(localTime.getHours()));
var localmnt:String = howlong(String(localTime.getMinutes()));
var localdaytext:String = getDayofWeekAsString(localTime.getDay());
var localdd:Number = localTime.getDate();
var localmm:String = getMonthAsString(myTime.getMonth());
var localyyyy:Number = localTime.getFullYear();
// convert local and country of origin times into strings and display in dynamic text boxes
var mytextdate:String = (hr+":"+mnt+" - "+daytext+", "+dd+" "+mm+" "+yyyy);
trace (mytextdate);
var localtextdate:String = (localhr+":"+localmnt+" - "+localdaytext+", "+localdd+" "+localmm+" "+localyyyy);
trace (localtextdate);
// function to include leading zero when hour < 10
function howlong(arg:String) {
if (length(arg) == 1) {
arg = "0"+arg;
return arg;
} else {
arg = arg;
return arg;
}
}
// function to return month value as a string
function getMonthAsString(month:Number):String {
var monthNames_array:Array = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
return monthNames_array[month];
}
// function to return day value as a string
function getDayofWeekAsString(day:Number):String {
var dayOfWeek_array:Array = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
return dayOfWeek_array[day];
}

glosrfc
October 27th, 2006, 07:39 PM
Here's the working example with changes

Edit: Just had a thought - it might be interesting for people to check out if this works in their different locations, especially before/after any daylight savings take effect in the next week or so. I have checked it by altering my own timezone settings and I'm assuming that Flash will compensate for any daylight saving effects.

It should show Hong Kong as being 8 hours ahead of GMT irrespective of where you are in the world so, if you're going to test it and you're not on GMT, you'll have to remember to compensate for your own GMT timezone offset as well.

glosrfc
October 30th, 2006, 06:01 PM
Phew...it still worked correctly for me after the clocks went back.

asteriks
October 31st, 2006, 11:35 PM
thanx .. will try it ... ... btw is that .fla a flash8 file ?

asteriks
November 1st, 2006, 02:24 AM
getting some error when i use the actionscript u mentioned be4.


**Error** Symbol=srch_grey, layer=actions, frame=1:Line 46: '{' expected
function getMonthAsString(month:Number):String {

**Error** Symbol=srch_grey, layer=actions, frame=1:Line 49: Unexpected '}' encountered
}

Total ActionScript Errors: 2 Reported Errors: 2

i am using this file to display time currently .

http://www.actionscript.org/resources/content_images/19/time_date_tut.zip

i am in GMT+5:30

i have still not tried the fla file u supplied yet, since i dont have flash8 now .. will download it today nd try the file u gave.