Difference between revisions of "LlGetDate"

From Second Life Wiki
Jump to navigation Jump to search
m
 
(18 intermediate revisions by 7 users not shown)
Line 2: Line 2:
|func_id=204|func_sleep=0.0|func_energy=10.0
|func_id=204|func_sleep=0.0|func_energy=10.0
|func=llGetDate|sort=GetDate|return_type=string
|func=llGetDate|sort=GetDate|return_type=string
|func_footnote=If you wish to know the time as well use: [[llGetTimestamp]] which uses the format "YYYY-MM-DDThh:mm:ss.ff..fZ"
|func_footnote=If you wish to know the time as well use: [[llGetTimestamp]] which uses the format {{NoWrap|"YYYY-MM-DDThh:mm:ss.ff..fZ"}}
|func_desc
|func_desc
|return_text=that is the current date in the UTC time zone in the format "YYYY-MM-DD".
|return_text=that is the current date in the UTC time zone in the format {{NoWrap|"YYYY-MM-DD"}}.
|spec
|spec
|caveats
|caveats
|constants
|constants
|examples=<pre>
|examples=<source lang="lsl2">// Birthday surprise
// Birthday surprise
default
default
{
{
Line 19: Line 18:
     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.  
     }
     }
}</source>
<source lang="lsl2">// 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))) | (year <= 1582))) && (month > 2));
}
}
</pre>
 
|helpers
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 " + (string) dayOfYear(year, month, day));
    }
}</source>
<source lang="lsl2">// Function to calculate whether a current year is a leap year
 
integer is_leap_year( integer year )
{   
    if( year % 4 )        return FALSE;  // Not a leap year under any circumstances   
    if( year <= 1582 )    return TRUE;    // In the Julian calender before 24 February 1582, every fourth year was a leap year
    if( !( year % 400 ))  return TRUE;    // A leap century is a leap year if divisible by 400
    if( !( year % 100 ))  return FALSE;  // Any other century is not a leap year 
    return TRUE;                          // It is divisible by 4 and not a century and not Julian, therefore it is a leap year
}</source>
 
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.
 
<source lang="lsl2">
    if (year % 4)          //  TRUE if NOT a leap year
</source>
 
|helpers=
=== Helper Functions ===
* [[Stamp2UnixInt|Timestamp: list format to Unix timestamp]] - ex: [2009, 2, 13, 3, 31, 30] to 1234567890
** compatible with [[llParseString2List]]( [[llGetDate]](), ["-"], [] ) (reports as first second of given day)
* [[Stamp2WeekdayStr|Timestamp: Weekday from (Y, M, D)]] - ex: "Friday" from (Y, M, D)
|also_functions={{LSL DefineRow||[[llGetTimestamp]]|Same format but with the time.}}
|also_functions={{LSL DefineRow||[[llGetTimestamp]]|Same format but with the time.}}
|also_events
|also_events
Line 34: Line 73:
|also_articles={{LSL DefineRow||[http://www.cl.cam.ac.uk/~mgk25/iso-time.html ISO 8601]|}}
|also_articles={{LSL DefineRow||[http://www.cl.cam.ac.uk/~mgk25/iso-time.html ISO 8601]|}}
|notes
|notes
|permission
|negative_index
|cat1=Time
|cat1=Time
|cat2
|cat2

Latest revision as of 00:47, 22 January 2015

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

// 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. 
    }
}
// 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))) | (year <= 1582))) && (month > 2));
}

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 " + (string) dayOfYear(year, month, day));
    }
}
// Function to calculate whether a current year is a leap year

integer is_leap_year( integer year ) 
{     
    if( year % 4 )         return FALSE;   // Not a leap year under any circumstances     
    if( year <= 1582 )     return TRUE;    // In the Julian calender before 24 February 1582, every fourth year was a leap year
    if( !( year % 400 ))   return TRUE;    // A leap century is a leap year if divisible by 400 
    if( !( year % 100 ))   return FALSE;   // Any other century is not a leap year  
    return TRUE;                           // It is divisible by 4 and not a century and not Julian, therefore it is a leap year
}

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.

    if (year % 4)          //  TRUE if NOT a leap year

Useful Snippets

Helper Functions

See Also

Functions

•  llGetTimestamp Same format but with the time.

Articles

•  ISO 8601

Deep Notes

Signature

function string llGetDate();