Difference between revisions of "LlGetDate"

From Second Life Wiki
Jump to navigation Jump to search
m
(Simple leap year calculation for 1901 to 2099)
Line 54: Line 54:
     return TRUE;                          // It is divisible by 4 and not a century and not Julian, therefore it is a leap year
     return TRUE;                          // It is divisible by 4 and not a century and not Julian, therefore it is a leap year
}</lsl>
}</lsl>
The previous script is way unnecessary for Avatar age, SL sales history etc. Here is all that is needed for 99% of SL applications.
This code is in fact valid for all years from 1901 to 2099, as 2000 was a leap year.
<lsl>
    if (year % 4)          //  TRUE if NOT a leap year
</lsl>
|helpers=
|helpers=
=== Helper Functions ===
=== Helper Functions ===

Revision as of 03:59, 31 December 2012

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 + (((month > 8) + month) / 2)
- ((1 + (((!(year % 4)) ^ (!(year % 100)) ^ (!(year % 400)))

Useful Snippets

Helper Functions

See Also

Functions

•  llGetTimestamp Same format but with the time.

Articles

•  ISO 8601

Deep Notes

Signature

function string llGetDate();