|
Winter Ventura
Eclectic Randomness
Join date: 18 Jul 2006
Posts: 2,579
|
01-30-2007 08:32
Remember that message board / LED reader board that we were working on?
I was out on a walk to McDonalds.. when I noticed the bank's message board. As I watched, the board told me about their low, fixed rate mortgages, and how I should buy a visa gift card for a loved-one today.. and then the board reminded me that it was 9:17pm, and told me the temperature.
Now.. I have no hope of trying to determine the temperature in SL.. nor really would I have any use for that information. But it WOULD be cool to display "SLT" as the message board looped it's message... sort of as a "message done (btw it's 8:30am)". Thing is.. the TIME function returns GMT.. which is useful, sortof.. except that the SLT clock (now labelled PST/PDT) is the one that everyone sees.
I'd like to generate a string, on the fly.. of the current "SL" time... adjusting automatically for Daylight savings time, and all that jazz. I don't need military time, or leading zeroes in the hour column.. Standard, good old, American time will be fine for my needs.
"9:04 pm" "12:00 am" (midnight) "12:00 pm" (noon)
Any ideas how to do this? Be great if it could be a single function that I could just call, and get the string defined (and this ready for sending to the linkset as normal)
_____________________
 ● Inworld Store: http://slurl.eclectic-randomness.com ● Website: http://www.eclectic-randomness.com ● Twitter: @WinterVentura
|
|
Baron Hauptmann
Just Designs / Scripter
Join date: 29 Oct 2005
Posts: 358
|
01-30-2007 09:24
Well, it's not just a simple function, but you could use llGetWallClock (seconds since midnight in sim), then calculate the current time . . .
Baron H.
|
|
Atashi Toshihiko
Frequently Befuddled
Join date: 7 Dec 2006
Posts: 1,423
|
01-30-2007 10:16
There's lots of clock examples in the Wiki. Not sure which or where any more though. I'm using the one that ends in org nowadays. I saw an example there just recently that provides the option to specify a time-zone and whether you want 12- or 24-hour time, and it's just a single function you can incorporate into any script.
-Atashi
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
hows this?
01-30-2007 12:20
Funny enough I put something similar together the other night. The clock code is a modified version of a script I picked up inworld ages ago. I'm afraid I've no record of who the orginal author was. // simple clock // // Editiable integer timeDiff = -5; // Hrs difference from GMT integer TwelveHrClock = TRUE;
// Constants integer OneMinute = 60; // Seconds in a Min ute integer OneHr = 3600; // Seconds in an Hr
//---------------------------------------------------------------------------------------- // // GetTime : Returns the current Time as as string in the hh:mm:ss format // string GetTime() { string ampm = ""; integer t = (integer) llGetGMTclock(); integer hours = t / OneHr; integer minutes = (t % OneHr) / OneMinute; integer seconds = t % OneMinute;
// Adjust for time zone hours += timeDiff; if(hours < 0)hours += 24; if(TwelveHrClock) { ampm = "am"; if(hours > 12) { hours -= 12; ampm = "pm"; } } string shours = (string)hours; string sminutes = (string)minutes; string sseconds = (string)seconds; //add zeros to single digit hrs/minutes/seconds if(!TwelveHrClock) { if(llStringLength(shours) == 1) { shours = "0" + shours; } } if(llStringLength(sminutes) == 1) { sminutes = "0" + sminutes; } if(llStringLength(sseconds) == 1) { sseconds = "0" + sseconds; } string timestr = shours + ":" + sminutes + ":" + sseconds + " " + ampm; return timestr; } //---------------------------------------------------------------------------------------- default { state_entry() { llSetTimerEvent(5); } timer() { llSetText(GetTime(),<1,1,1>,1); } }
|
|
Peekay Semyorka
Registered User
Join date: 18 Nov 2006
Posts: 337
|
01-30-2007 18:30
Use this version, it handles daylight saving time correctly: // get current time string string getCurrentTime() { integer now = (integer) llGetWallclock();
// construct hours integer hours = now / 3600; if (hours == 0) hours = 12; else if (hours > 12) hours -= 12; string currentTime = (string)hours + ":";
// construct minutes integer minutes = (now % 3600) / 60; if (minutes < 10) { currentTime += "0"; } currentTime += (string)minutes; // construct am/pm if (now < 3600*12) currentTime += " am"; else currentTime += " pm"; return currentTime; }
|