Difference between revisions of "Clock"

From Second Life Wiki
Jump to navigation Jump to search
Line 3: Line 3:
=====Say the current time (PST)=====
=====Say the current time (PST)=====
<pre>
<pre>
//Simple clock by Beverly Larkin to show example of how to use llGetWallClock()
//Simple clock by Beverly Larkin to show example of how to use llGetWallClock()


Line 36: Line 35:
             }
             }
         }
         }
        if(M < 10)
         {
         {
             llOwnerSay((string)H + ":" + "0" + (string)M + AP); //if the mintues is less than 10 add the extra 0 (so it doesn't say 1:3PM) for example
             llOwnerSay((string)H + ":" + "0" + (string)M + AP); //if the mintues is less than 10 add the extra 0 (so it doesn't say 1:3PM) for example
Line 45: Line 45:
     }
     }
}
}
</pre>
</pre>


[[Category:LSL Examples]]
[[Category:LSL Examples]]

Revision as of 11:08, 28 February 2007

Say the current time (PST)
//Simple clock by Beverly Larkin to show example of how to use llGetWallClock()

integer H; //Hours
integer M; //Minutes
string AP; //AM or PM

default
{
    state_entry()
    {
        integer T = (integer)llGetWallclock(); // Get time PST
        if (T > 43200) //If it's after noon
        {
            T = T - 43200; //Subtract 12 hours
            AP = "PM";  //set to PM
            H = T / 3600; //get hours
            M = (T - (H * 3600)) / 60; //get minutes
            if(H == 0) //if the hour is 0
            {
                H = 12; // make the hour 12
            }
        }
        else
        {
            AP = "AM"; //set to AM
            H = T / 3600; //get the hour
            M = (T - (H * 3600)) / 60; //get minutes
            if(H == 0) //if the hour is 0
            {
                H = 12; // make the hour 12
            }
        }
        if(M < 10)
        {
            llOwnerSay((string)H + ":" + "0" + (string)M + AP); //if the mintues is less than 10 add the extra 0 (so it doesn't say 1:3PM) for example
        }
        else
        {
            llOwnerSay((string)H + ":" + (string)M + AP); // otherwise just say the time
        }
    }
}