Difference between revisions of "LlGetDate"

From Second Life Wiki
Jump to navigation Jump to search
(Added function to calculate the day of year.)
m (missing return type)
Line 19: Line 19:
     timer()
     timer()
     {
     {
         if(llGetDate() == "1987-02-15")
         if(llGetDate() == "2009-02-15")
             llSetText("HAPPY BIRTHDAY!", <0,1,0>, 1.0);
             llSetText("HAPPY BIRTHDAY!", <0,1,0>, 1.0);
         else
         else
             llSetText("A surprise is comming...", <0,1,0>, 1.0);
             llSetText("A surprise is coming...", <0,1,0>, 1.0);
          
          
         llSetTimerEvent(3600);  // check every hour.  
         llSetTimerEvent(3600.0);  // check every hour.  
     }
     }
}
}
Line 30: Line 30:
<lsl>
<lsl>
// Function to calculate the numeric day of year
// Function to calculate the numeric day of year
dayOfYear(integer year, integer month, integer day)
integer dayOfYear(integer year, integer month, integer day)
{
{
     return
     return
Line 43: Line 43:
     {
     {
         list dateComponents = llParseString2List(llGetDate(), ["-"], []);
         list dateComponents = llParseString2List(llGetDate(), ["-"], []);
         integer year = (integer) llList2String(dateComponents, 0);
         integer year = (integer) llList2String(dateComponents, 0);
         integer month = (integer) llList2String(dateComponents, 1);
         integer month = (integer) llList2String(dateComponents, 1);
         integer day = (integer) llList2String(dateComponents, 2);
         integer day   = (integer) llList2String(dateComponents, 2);
         llSay(0, "The current day of the year is " + dayOfYear(year, month, day));
         llSay(0, "The current day of the year is " + dayOfYear(year, month, day));
     }
     }

Revision as of 02:16, 2 July 2008

Summary

Function: string llGetDate( );
0.0 Forced Delay
10.0 Energy

Returns a string that is the current date in the UTC time zone in the format "YYYY-MM-DD".

If you wish to know the time as well use: llGetTimestamp which uses the format "YYYY-MM-DDThh:mm:ss.ff..fZ"

Examples

<lsl> // Birthday surprise default {

   state_entry()
   {   
       llSetTimerEvent(0.1);
   }
   timer()
   {
       if(llGetDate() == "2009-02-15")
           llSetText("HAPPY BIRTHDAY!", <0,1,0>, 1.0);
       else
           llSetText("A surprise is coming...", <0,1,0>, 1.0);
        
       llSetTimerEvent(3600.0);  // check every hour. 
   }

} </lsl> <lsl> // Function to calculate the numeric day of year integer dayOfYear(integer year, integer month, integer day) {

   return
         day
       + (month - 1) * 30 - (2 - ((year % 4) == 0) * ((year % 100) != 0)) * (month > 2)
       + (month / 2) * (month <= 8) + (4 + (month - 7) / 2) * (month > 8);

}

default {

   touch_end(integer count)
   {
       list dateComponents = llParseString2List(llGetDate(), ["-"], []);
       integer year  = (integer) llList2String(dateComponents, 0);
       integer month = (integer) llList2String(dateComponents, 1);
       integer day   = (integer) llList2String(dateComponents, 2);
       llSay(0, "The current day of the year is " + dayOfYear(year, month, day));
   }

}

</lsl>

See Also

Functions

•  llGetTimestamp Same format but with the time.

Articles

•  ISO 8601

Deep Notes

Signature

function string llGetDate();