View Full Version : Clock Help
jimmiec
05-24-2006, 09:52 AM
Can anyone give the script or code to put a simle clock on my project.
I want to run it with a border or flat. Digital preferably.I need to get system time but dont know how to write it.If I just put in get system time on startup
it shows nothing. Something so simple makes me feel so stupid
Thanks for any Help
Jim
bobbie
05-24-2006, 10:00 AM
HaVe a look here (http://www.mina-e.com/ams-examples.html).
Here's my contribution. I was using a Flash clock until a little while ago in one of my applications, but I didn't want to have any Flash dependencies, just for a clock. :)
On Startup:
sdayofweek1 = "Sunday";
sdayofweek2 = "Monday";
sdayofweek3 = "Tuesday";
sdayofweek4 = "Wednesday";
sdayofweek5 = "Thursday";
sdayofweek6 = "Friday";
sdayofweek7 = "Saturday";
smonth1 = "January";
smonth2 = "February";
smonth3 = "March";
smonth4 = "April";
smonth5 = "May";
smonth6 = "June";
smonth7 = "July";
smonth8 = "August";
smonth9 = "September";
smonth10 = "October";
smonth11 = "November";
smonth12 = "December";
On Preload:
Paragraph.SetText("ParagraphTime", System.GetTime(TIME_FMT_AMPM));
sdayofweek = System.GetDate(DATE_FMT_DAYOFWEEK);
if sdayofweek == "1" then
sdayofweek = sdayofweek1
elseif sdayofweek == "2" then
sdayofweek = sdayofweek2
elseif sdayofweek == "3" then
sdayofweek = sdayofweek3
elseif sdayofweek == "4" then
sdayofweek = sdayofweek4
elseif sdayofweek == "5" then
sdayofweek = sdayofweek5
elseif sdayofweek == "6" then
sdayofweek = sdayofweek6
elseif sdayofweek == "7" then
sdayofweek = sdayofweek7
end
smonth = System.GetDate(DATE_FMT_MONTH);
if smonth == "01" then
smonth = smonth1
elseif smonth == "02" then
smonth = smonth2
elseif smonth == "03" then
smonth = smonth3
elseif smonth == "04" then
smonth = smonth4
elseif smonth == "05" then
smonth = smonth5
elseif smonth == "06" then
smonth = smonth6
elseif smonth == "07" then
smonth = smonth7
elseif smonth == "08" then
smonth = smonth8
elseif smonth == "09" then
smonth = smonth9
elseif smonth == "10" then
smonth = smonth10
elseif smonth == "11" then
smonth = smonth11
elseif smonth == "12" then
smonth = smonth12
end
sdaytemp = System.GetDate(DATE_FMT_DAY);
nleadingzero = String.Find(sdaytemp, "0", 1, false);
if nleadingzero == 1 then
sday = String.Right(sdaytemp, 1);
else
sday = sdaytemp;
end
syear = System.GetDate(DATE_FMT_YEAR);
Paragraph.SetText("ParagraphDate", sdayofweek.." "..smonth.." "..sday..", "..syear);
On Show:
Page.StartTimer(250);
On Timer:
Paragraph.SetText("ParagraphTime", System.GetTime(TIME_FMT_AMPM));
sdayofweek = System.GetDate(DATE_FMT_DAYOFWEEK);
if sdayofweek == "1" then
sdayofweek = sdayofweek1
elseif sdayofweek == "2" then
sdayofweek = sdayofweek2
elseif sdayofweek == "3" then
sdayofweek = sdayofweek3
elseif sdayofweek == "4" then
sdayofweek = sdayofweek4
elseif sdayofweek == "5" then
sdayofweek = sdayofweek5
elseif sdayofweek == "6" then
sdayofweek = sdayofweek6
elseif sdayofweek == "7" then
sdayofweek = sdayofweek7
end
smonth = System.GetDate(DATE_FMT_MONTH);
if smonth == "01" then
smonth = smonth1
elseif smonth == "02" then
smonth = smonth2
elseif smonth == "03" then
smonth = smonth3
elseif smonth == "04" then
smonth = smonth4
elseif smonth == "05" then
smonth = smonth5
elseif smonth == "06" then
smonth = smonth6
elseif smonth == "07" then
smonth = smonth7
elseif smonth == "08" then
smonth = smonth8
elseif smonth == "09" then
smonth = smonth9
elseif smonth == "10" then
smonth = smonth10
elseif smonth == "11" then
smonth = smonth11
elseif smonth == "12" then
smonth = smonth12
end
sdaytemp = System.GetDate(DATE_FMT_DAY);
nleadingzero = String.Find(sdaytemp, "0", 1, false);
if nleadingzero == 1 then
sday = String.Right(sdaytemp, 1);
else
sday = sdaytemp;
end
syear = System.GetDate(DATE_FMT_YEAR);
Paragraph.SetText("ParagraphDate", sdayofweek.." "..smonth.." "..sday..", "..syear);
I hope this helps.
Hey Tek,
You could reduce the number of evaluations in that code (and probably improve performance) by indexing the day/month names into tables and accessing them directly via their index.
Something like this:
On Startup
tdayofweek[1] = "Sunday";
tdayofweek[2] = "Monday";
tdayofweek[3] = "Tuesday";
tdayofweek[4] = "Wednesday";
tdayofweek[5] = "Thursday";
tdayofweek[6] = "Friday";
tdayofweek[7] = "Saturday";
tmonth[1] = "January";
tmonth[2] = "February";
tmonth[3] = "March";
tmonth[4] = "April";
tmonth[5] = "May";
tmonth[6] = "June";
tmonth[7] = "July";
tmonth[8] = "August";
tmonth[9] = "September";
tmonth[10] = "October";
tmonth[11] = "November";
tmonth[12] = "December";
On Show/On Timer
Paragraph.SetText("ParagraphTime", System.GetTime(TIME_FMT_AMPM));
sdayofweek = tdayofweek[System.GetDate(DATE_FMT_DAYOFWEEK)];
smonth = tmonth[System.GetDate(DATE_FMT_MONTH)];
sdaytemp = System.GetDate(DATE_FMT_DAY);
nleadingzero = String.Find(sdaytemp, "0", 1, false);
if nleadingzero == 1 then
sday = String.Right(sdaytemp, 1);
else
sday = sdaytemp;
end
syear = System.GetDate(DATE_FMT_YEAR);
Paragraph.SetText("ParagraphDate", sdayofweek.." "..smonth.." "..sday..", "..syear);
Hi TJS,
You're right... that would make it easier and probably faster, except for the fact that the month returned by System.GetDate(DATE_FMT_MONTH) returns two characters for the month. It would work for the day of the week though. :)
This works better (good catch tek):
tdayofweek = {};
tdayofweek[1] = "Sunday";
tdayofweek[2] = "Monday";
tdayofweek[3] = "Tuesday";
tdayofweek[4] = "Wednesday";
tdayofweek[5] = "Thursday";
tdayofweek[6] = "Friday";
tdayofweek[7] = "Saturday";
tmonth = {};
tmonth[1] = "January";
tmonth[2] = "February";
tmonth[3] = "March";
tmonth[4] = "April";
tmonth[5] = "May";
tmonth[6] = "June";
tmonth[7] = "July";
tmonth[8] = "August";
tmonth[9] = "September";
tmonth[10] = "October";
tmonth[11] = "November";
tmonth[12] = "December";
Paragraph.SetText("ParagraphTime", System.GetTime(TIME_FMT_AMPM));
sdayofweek = tdayofweek[String.ToNumber(System.GetDate(DATE_FMT_DAYOFWEEK) )];
smonth = tmonth[String.ToNumber(System.GetDate(DATE_FMT_MONTH))];
sdaytemp = System.GetDate(DATE_FMT_DAY);
nleadingzero = String.Find(sdaytemp, "0", 1, false);
if nleadingzero == 1 then
sday = String.Right(sdaytemp, 1);
else
sday = sdaytemp;
end
syear = System.GetDate(DATE_FMT_YEAR);
Paragraph.SetText("ParagraphDate", sdayofweek.." "..smonth.." "..sday..", "..syear);
Now you're talkin'! That code works just fine, and I think I'll use it! :)
Thanks TJS. :yes
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.