Difference between revisions of "LlGetGMTclock"

From Second Life Wiki
Jump to navigation Jump to search
m
 
(6 intermediate revisions by 4 users not shown)
Line 2: Line 2:
|func_id=282|func_sleep=0.0|func_energy=10.0
|func_id=282|func_sleep=0.0|func_energy=10.0
|func=llGetGMTclock|return_type=float
|func=llGetGMTclock|return_type=float
|func_footnote=For PST use [[llGetWallclock]]
|func_footnote=For SL time, which is the same as California time, use [[llGetWallclock]]
|func_desc
|func_desc
|return_text=that is the time in seconds since midnight GMT
|return_text=that is the time in seconds since midnight GMT.  Value appears to be truncated to the second.
|spec
|spec
|caveats
|caveats
|constants
|constants
|examples
|examples=
<source lang="lsl2">
//--// GMT function with local offsets in 12hr format //--//
integer gIntMinute = 60;    //-- 1 minute in seconds
integer gIntHour  = 3600;  //-- 1 hour in seconds
integer gInt12Hr  = 43200; //-- 12hrs in seconds
integer gIntDay    = 86400; //-- 1 day in seconds
string fStrGMTwOffset( integer vIntLocalOffset ){
  //-- get the correct time in seconds for the given offset
  integer vIntBaseTime = ((integer)llGetGMTclock() + gIntDay + vIntLocalOffset * gIntHour) % gIntDay;
  string vStrReturn;
  //-- store morning or night and reduce to 12hour format if needed
  if (vIntBaseTime < gInt12Hr){
    vStrReturn = " AM";
  }else{
    vStrReturn = " PM";
    vIntBaseTime = vIntBaseTime % gInt12Hr;
  }
  //-- get and format minutes
  integer vIntMinutes = (vIntBaseTime % gIntHour) / gIntMinute;
  vStrReturn = (string)vIntMinutes + vStrReturn;
  if (10 > vIntMinutes){
    vStrReturn = "0" + vStrReturn;
  }
  //-- add in the correct hour, force 0 to 12
  if (vIntBaseTime < gIntHour){
    vStrReturn = "12:" + vStrReturn;
  }else{
    vStrReturn = (string)(vIntBaseTime / gIntHour) + ":" + vStrReturn;
  }
  return vStrReturn;
}
default{
  touch_start( integer vIntTouched ){
    //-- '-8' is california time, no adjustment for DST
    llSay( 0, "The time is now " + fStrGMTwOffset( -8 ) );
  }
}
</source>
<source lang="lsl2">
// Gets the number of milliseconds since midnight UTC.
integer GetGMTmsclock()
{
    string stamp = llGetTimestamp();
    return
        (integer) llGetSubString(stamp, 11, 12) * 3600000 +
        (integer) llGetSubString(stamp, 14, 15) * 60000 +
        llRound((float) llGetSubString(stamp, 17, -2) * 1000.0);
}
</source>
|helpers
|helpers
|also_functions=
|also_functions=
{{LSL DefineRow||[[llGetWallclock]]|Seconds since midnight PST}}
{{LSL DefineRow||[[llGetWallclock]]|Seconds since midnight SLT (i.e. PST or PDT) }}
|also_events
|also_events
|also_tests
|also_tests

Latest revision as of 00:55, 22 January 2015

Summary

Function: float llGetGMTclock( );
0.0 Forced Delay
10.0 Energy

Returns a float that is the time in seconds since midnight GMT. Value appears to be truncated to the second.

For SL time, which is the same as California time, use llGetWallclock

Examples

//--// GMT function with local offsets in 12hr format //--//
 
integer gIntMinute = 60;    //-- 1 minute in seconds
integer gIntHour   = 3600;  //-- 1 hour in seconds
integer gInt12Hr   = 43200; //-- 12hrs in seconds
integer gIntDay    = 86400; //-- 1 day in seconds
 
string fStrGMTwOffset( integer vIntLocalOffset ){
   //-- get the correct time in seconds for the given offset
  integer vIntBaseTime = ((integer)llGetGMTclock() + gIntDay + vIntLocalOffset * gIntHour) % gIntDay;
  string vStrReturn;
 
   //-- store morning or night and reduce to 12hour format if needed
  if (vIntBaseTime < gInt12Hr){
    vStrReturn = " AM";
  }else{
    vStrReturn = " PM";
    vIntBaseTime = vIntBaseTime % gInt12Hr;
  }
 
   //-- get and format minutes
  integer vIntMinutes = (vIntBaseTime % gIntHour) / gIntMinute;
  vStrReturn = (string)vIntMinutes + vStrReturn;
  if (10 > vIntMinutes){
    vStrReturn = "0" + vStrReturn;
  }
 
   //-- add in the correct hour, force 0 to 12
  if (vIntBaseTime < gIntHour){
    vStrReturn = "12:" + vStrReturn;
  }else{
    vStrReturn = (string)(vIntBaseTime / gIntHour) + ":" + vStrReturn;
  }
  return vStrReturn;
}
 
default{
  touch_start( integer vIntTouched ){
     //-- '-8' is california time, no adjustment for DST
    llSay( 0, "The time is now " + fStrGMTwOffset( -8 ) );
  }
}
// Gets the number of milliseconds since midnight UTC.
integer GetGMTmsclock()
{
    string stamp = llGetTimestamp();
    return
        (integer) llGetSubString(stamp, 11, 12) * 3600000 +
        (integer) llGetSubString(stamp, 14, 15) * 60000 +
        llRound((float) llGetSubString(stamp, 17, -2) * 1000.0);
}

See Also

Functions

•  llGetWallclock Seconds since midnight SLT (i.e. PST or PDT)

Deep Notes

Signature

function float llGetGMTclock();