Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Converting llGetTimeOfDay to hrs/mins?

BushidoBrown Hightower
lat 42.36 / long -71.05
Join date: 16 Feb 2006
Posts: 31
02-25-2006 21:35
I just started to get down with LSL today and was looking to hack up a module that can give me things like time of day in the sim I'm in, location, etc, etc. I've seen alot of threads alluding to some of these things, but none that could tell me how to convert the output of llGetTimeOfDay() to hrs/mins. Here's what I have so far:

CODE

default
{
state_entry()
{

}

touch_start(integer total_number)
{
float time = llGetTimeOfDay();
llSay(0, "The time is " + (string)time);
}
}


'preciate any science someone can drop on me regarding this. I expect to be posting more in terms of calls for clue as I get up to speed on LSL. Until then, be easyl.
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
02-25-2006 21:55
the same way as the example of llGetWallClock on the wiki, but it only deals with sim time, which 1 day is 4 hours long and it goes to 0 apon a sim reset ect

CODE

integer simtime;
integer h;
integer m;
integer s;
default
{
touch_start(integer total_number)
{
simtime = (integer)llGetTimeOfDay();
h = simtime/3600;
m = (simtime%3600)/60;
s = simtime%60;
llSay(0,(string)h+":"+(string)m+":"+(string)s);
}
}
BushidoBrown Hightower
lat 42.36 / long -71.05
Join date: 16 Feb 2006
Posts: 31
02-26-2006 00:12
Thanks for the clue Osgeld. I noticed that the output for say, 8:01:02 is displayed as: 8:1:2. Is there a way around that?
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
02-26-2006 03:17
Yes, there is, but it's a fiddle.

You need to typecast the minutes and seconds to strings, check their length, and if it's 1 add a 0 in front.

Something like this snippet:
CODE
string min=(string)m;
if(llStringLength(min)==1)
{
min="0"+min;
}


You can actually define that as a function if you want (since you'll do the same for seconds too, or as it's so short just write it again) and your output string would become llSay(0, (string)h+":"+min+":"+sec);
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
02-26-2006 07:24
Silly question but why not use llGetTimestamp?
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
BushidoBrown Hightower
lat 42.36 / long -71.05
Join date: 16 Feb 2006
Posts: 31
02-26-2006 09:50
From: Strife Onizuka
Silly question but why not use llGetTimestamp?


Hmm, I guess my assumption was that it wouldn't give you actual time in SL for the particular sim you're in. I thought it was based on RL time.