Difference between revisions of "Clock"

From Second Life Wiki
Jump to navigation Jump to search
m
m (<lsl> tag to <source>)
 
(2 intermediate revisions by one other user not shown)
Line 2: Line 2:


=====Show the current SL time (PST/PDT)=====
=====Show the current SL time (PST/PDT)=====
<lsl>
<source lang="lsl2">
// Simple SLT 12-hour clock with AM/PM and PDT/PST indicators.  Uses llGetWallClock() and llGetGMTclock()
// Simple SLT 12-hour clock with AM/PM and PDT/PST indicators.  Uses llGetWallClock() and llGetGMTclock()
// Omei Qunhua
// Omei Qunhua
Line 14: Line 14:
     timer()
     timer()
     {
     {
         integer Hours;
         integer sltSecs = (integer) llGetWallclock();               // Get SL time in seconds (will be either PST or PDT)
        integer Mins;
        integer diff    = (integer) llGetGMTclock() - sltSecs;      // Compute the difference between UTC and SLT
        string  AMPM;
         string  PST_PDT = " PST";                                   // Assume Pacific Standard Time
        float  fSecs = llGetWallclock();             // Get SL time in seconds (will be either PST or PDT)
 
         string  PST_PDT = " PST";                     // Assume Pacific Standard Time
         // If the difference between SLT and UTC is 7 hours or -17 hours, then SLT is currently PDT
         if ( (llGetGMTclock() - fSecs) < 27000.0)    // If difference between SLT and UTC is less then 7.5 hours, then SLT is currently PDT
        if (diff == 25200 || diff == -61200)       
             PST_PDT = " PDT";                        //  Pacific Daylight Time
             PST_PDT = " PDT";                        //  Pacific Daylight Time
         Mins   = (integer) fSecs / 60;
         integer Mins = sltSecs / 60;
         Hours   = Mins / 60;
         integer Hours = Mins / 60;
         Mins   = Mins % 60;
         Mins = Mins % 60;
         AMPM   = " AM";
         string AMPM = " AM";
         if (Hours > 11)            // Convert to 12-hour format with PM indication
         if (Hours > 11)            // Convert to 12-hour format with PM indication
         {
         {
Line 35: Line 35:
     }
     }
}
}
</lsl>
</source>


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

Latest revision as of 14:16, 24 January 2015

Show the current SL time (PST/PDT)
// Simple SLT 12-hour clock with AM/PM and PDT/PST indicators.   Uses llGetWallClock() and llGetGMTclock()
// Omei Qunhua

default
{
    state_entry()
    {
        llSetTimerEvent(1);
    }
    timer()
    {
        integer sltSecs = (integer) llGetWallclock();               // Get SL time in seconds (will be either PST or PDT)
        integer diff    = (integer) llGetGMTclock() - sltSecs;      // Compute the difference between UTC and SLT
        string  PST_PDT = " PST";                                   // Assume Pacific Standard Time

        // If the difference between SLT and UTC is 7 hours or -17 hours, then SLT is currently PDT
        if (diff == 25200 || diff == -61200)         
            PST_PDT = " PDT";                         //  Pacific Daylight Time
        integer Mins  = sltSecs / 60;
        integer Hours = Mins / 60;
        Mins = Mins % 60;
        string AMPM = " AM";
        if (Hours > 11)            // Convert to 12-hour format with PM indication
        {
            AMPM = " PM";
            Hours -= 12;
        }
        if (Hours == 0)
            Hours = 12;
        llSetText( (string) Hours + ":" + llGetSubString("0" + (string) Mins,  -2, -1) + AMPM + PST_PDT, <1,1,1> ,1);
    }
}