LSL Wiki Mirror 10-5-2006: llGetGMTclock

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings ::
float llGetGMTclock()

Gets the time in seconds since midnight in GMT/UTC.

This is great for a monotonic source of time that ticks once a second. GMT time is very useful when synchronizing with systems outside of SL via email or RPC. It is an absolute and international measure of time that does not change throughout the year. It isn't so great when trying to make a wall clock for Second Life that observes Daylight Saving Time. Creating local time from this function is a matter of adding the correct offset to GMT, a requirement complicated by yearly and national differences of when Daylight Saving Time goes into and out of effect.

The following function gets a clock for any time zone in the world, with a military time toggle.
(by DanielLuchador)

string clock(float timezone, integer military)
{
    integer raw = (integer)(llGetGMTclock() + (timezone * 3600));
    integer shiftraw = raw;

      //  3600 = seconds in an hour
      // 86400 = seconds in 24 hours
    if((timezone * 3600) + raw > 86400)
    {
        shiftraw = raw - 86400;
    }
    else if((timezone * 3600) + raw < 0)
    {
        shiftraw = raw + 86400;
    }
    
    integer hours = shiftraw / 3600;
    integer minutes = (shiftraw % 3600) / 60;
    integer seconds = shiftraw % 60;
    string ampm;
    
    //non-military time adjustments
    if(!military)
    {
          // 43200 = seconds in 12 hours
        if(shiftraw < 43200)
        {
            ampm = " AM";
        }
        else
        {
            ampm = " PM";
            hours -= 12;
        }
    }
    
    string shours = (string)hours;
    string sminutes = (string)minutes;
    string sseconds = (string)seconds;
    
    //add zeros to single digit minutes/seconds
    if(llStringLength(sminutes) == 1)
    {
        sminutes = "0" + sminutes;
    }
    if(llStringLength(sseconds) == 1)
    {
        sseconds = "0" + sseconds;
    }
    
    string time = shours + ":" + sminutes + ":" + sseconds + ampm;
    
    return time;
}

See also: llGetWallclock (returns time in seconds in the PST/PDT time zone).


Functions | Time | Simulator
There is one comment on this page. [Display comments/form]