Difference between revisions of "LlGetWallclock"

From Second Life Wiki
Jump to navigation Jump to search
m (Oops.. fixing extra 'default' state that I pasted.)
 
(10 intermediate revisions by 7 users not shown)
Line 4: Line 4:
|func_footnote=For GMT use [[llGetGMTclock]]
|func_footnote=For GMT use [[llGetGMTclock]]
|func_desc
|func_desc
|return_text=that is the time in seconds since midnight Pacific time (PST/PDT), truncated to whole seconds.
|return_text=that is the time in seconds since midnight Pacific time (PST/PDT), truncated to whole seconds. That is the same as the time of day in SLT expressed as seconds.
|spec
|spec
|caveats
|caveats
|constants
|constants
|examples=<lsl>// Real World Sun
|examples=<source lang="lsl2">// Real World Sun
integer set;
integer Flag;


default
default
Line 15: Line 15:
     state_entry()
     state_entry()
     {
     {
        Flag = -1;
         llSetTimerEvent(0.1);
         llSetTimerEvent(0.1);
        set = -1;
     }
     }
      
      
Line 22: Line 22:
     {
     {
         float time = llGetWallclock();
         float time = llGetWallclock();
         if(set == -1)
         if (Flag == -1)
        {
             llSetTimerEvent(60.0);
             llSetTimerEvent(60.0);
         if(time < 21600)
        }
         if (time < 21600)
         {
         {
             if(set)
             if (Flag)
             {
             {
                 llSetText("The Sun is coming! :)", <1,1,0>, 1.0);
                 llSetText("The Sun is coming! :)", <1,1,0>, 1.0);
                 set = 0;
                 Flag = 0;
             }
             }
         }
         }
         else if(time < 64800)
         else if (time < 64800)
         {
         {
             if(set != 1)
             if (Flag != 1)
             {
             {
                 llSetText("Sun has risen. :(", <1,0,0>, 1.0);
                 llSetText("Sun has risen. :(", <1,0,0>, 1.0);
                 set = 1;
                 Flag = 1;
             }
             }
         }
         }
         else if(set != 2)
         else if (Flag != 2)
         {
         {
             llSetText("Goodbye Sun. :(", <1,0,0>, 1.0);
             llSetText("Goodbye Sun. :(", <1,0,0>, 1.0);
             set = 2;
             Flag = 2;
         }
         }
     }
     }
}</lsl>
}</source>
 
<source lang="lsl2">// Convert to human-readable HH:MM:SS format
string ConvertWallclockToTime()
{
    integer now = (integer)llGetWallclock();
    integer seconds = now % 60;
    integer minutes = (now / 60) % 60;
    integer hours = now / 3600;
    return llGetSubString("0" + (string)hours, -2, -1) + ":"
        + llGetSubString("0" + (string)minutes, -2, -1) + ":"
        + llGetSubString("0" + (string)seconds, -2, -1);
}
 
default
{
    touch_start(integer total_number)
    {
        llSay(0, ConvertWallclockToTime());
    }
}
</source>
 
<source lang="lsl2">// Convert to human-readable 12-hour HH:MM:SS (AM/PM) format
string ConvertWallclockToTime()
{
    integer now = (integer)llGetWallclock();
    integer seconds = now % 60;
    integer minutes = (now / 60) % 60;
    integer hours = now / 3600;
 
    return llGetSubString("0" + (string)(hours % 12), -2, -1) + ":"
          + llGetSubString("0" + (string)minutes, -2, -1) + ":"
          + llGetSubString("0" + (string)seconds, -2, -1) + " "
          + llList2String(["AM", "PM"], (hours > hours % 12));
}
 
default
{
    touch_start(integer total_number)
    {
        llSay(0, ConvertWallclockToTime());
    }
}
</source>
 
 
|helpers
|helpers
|also_functions=
|also_functions=
Line 53: Line 101:
|also_tests
|also_tests
|also_articles
|also_articles
|notes
|notes=To determine if the current time returned by this function is PST or PDT, you can look at the difference between llGetGMTclock() and llGetWallclock(). The difference will be either 8 hours or -16 hours for PST, and 7 hours or -17 hours for PDT, that is 28800 or -57600,  or 25200 or -61200 seconds.
|permission
|permission
|negative_index
|negative_index

Latest revision as of 08:34, 6 September 2023

Summary

Function: float llGetWallclock( );

Returns a float that is the time in seconds since midnight Pacific time (PST/PDT), truncated to whole seconds. That is the same as the time of day in SLT expressed as seconds.

For GMT use llGetGMTclock

Examples

// Real World Sun
integer Flag;

default
{
    state_entry()
    {
        Flag = -1;
        llSetTimerEvent(0.1);
    }
    
    timer()
    {
        float time = llGetWallclock();
        if (Flag == -1)
        {
            llSetTimerEvent(60.0);
        }
        if (time < 21600)
        {
            if (Flag)
            {
                llSetText("The Sun is coming! :)", <1,1,0>, 1.0);
                Flag = 0;
            }
        }
        else if (time < 64800)
        {
            if (Flag != 1)
            {
                llSetText("Sun has risen. :(", <1,0,0>, 1.0);
                Flag = 1;
            }
        }
        else if (Flag != 2)
        {
            llSetText("Goodbye Sun. :(", <1,0,0>, 1.0);
            Flag = 2;
        }
    }
}
// Convert to human-readable HH:MM:SS format
string ConvertWallclockToTime()
{
    integer now = (integer)llGetWallclock();
    integer seconds = now % 60;
    integer minutes = (now / 60) % 60;
    integer hours = now / 3600;
    return llGetSubString("0" + (string)hours, -2, -1) + ":" 
        + llGetSubString("0" + (string)minutes, -2, -1) + ":" 
        + llGetSubString("0" + (string)seconds, -2, -1);
}

default
{
    touch_start(integer total_number)
    {
        llSay(0, ConvertWallclockToTime());
    }
}
// Convert to human-readable 12-hour HH:MM:SS (AM/PM) format
string ConvertWallclockToTime()
{
    integer now = (integer)llGetWallclock();
    integer seconds = now % 60;
    integer minutes = (now / 60) % 60;
    integer hours = now / 3600;

    return llGetSubString("0" + (string)(hours % 12), -2, -1) + ":" 
           + llGetSubString("0" + (string)minutes, -2, -1) + ":"
           + llGetSubString("0" + (string)seconds, -2, -1) + " "
           + llList2String(["AM", "PM"], (hours > hours % 12));
}

default
{
    touch_start(integer total_number)
    {
        llSay(0, ConvertWallclockToTime());
    }
}

Notes

To determine if the current time returned by this function is PST or PDT, you can look at the difference between llGetGMTclock() and llGetWallclock(). The difference will be either 8 hours or -16 hours for PST, and 7 hours or -17 hours for PDT, that is 28800 or -57600, or 25200 or -61200 seconds.

See Also

Functions

•  llGetGMTclock Seconds since midnight GMT

Deep Notes

Search JIRA for related Issues

Signature

function float llGetWallclock();