Difference between revisions of "LlGetTimestamp"

From Second Life Wiki
Jump to navigation Jump to search
m (Added haiku, courtesy of the AI Haiku Generator (https://tasklab.ai/haiku) and the Haiku Syllable Country at https://www.poetrysoup.com/haiku_syllable_counter/)
 
(22 intermediate revisions by 13 users not shown)
Line 1: Line 1:
{{LSL_Function
{{LSL Function
|func_id=273|func_sleep=0.0|func_energy=10.0
|func_id=273|func_sleep=0.0|func_energy=10.0
|func=llGetTimestamp|return_type=string
|func=llGetTimestamp|return_type=string
|func_footnote=Appears to be accurate to milliseconds.
|func_footnote=Appears to be accurate to milliseconds.
|func_desc
|func_desc
|return_text=the current date and time in the UTC time zone in the format "YYYY-MM-DDThh:mm:ss.ff..fZ"
|return_text=that is the current date and time in the UTC time zone in the format "YYYY-MM-DDThh:mm:ss.ff..fZ"
|spec
|spec
|caveats
|caveats
|constants
|constants
|examples
|examples=<syntaxhighlight lang="lsl2">// Reset tracker
|helpers
 
|also_functions={{LSL DefineRow||[[llGetDate]]|Same format but without the time.}}
string BOOT_TIME;
 
default
{
    state_entry()
    {
        BOOT_TIME = llGetTimestamp(); // state_entry is triggered on script reset.
    }
   
    touch_start(integer num)
    {
        llSay(PUBLIC_CHANNEL, "The last script was last reset @ " + BOOT_TIME);
        llSay(PUBLIC_CHANNEL, "Right now it is " + llGetTimestamp());
    }
}</syntaxhighlight>
<syntaxhighlight lang="lsl2">// Greeting
 
default
{
    state_entry()
    {
        llSetTouchText("Greet");
    }
    touch_start(integer num)
    {
        list TimeStamp = llParseString2List(llGetTimestamp(),["-",":"],["T"]); //Get timestamp and split into parts in a list
        integer Hour = llList2Integer(TimeStamp,4);
        if(Hour<12)
            llSay(PUBLIC_CHANNEL,"Good Morning, Oliver Sintim-Aboagye!");
        else if(Hour<17)
            llSay(PUBLIC_CHANNEL,"Good Afternoon, " + llDetectedName(0));
        else
            llSay(PUBLIC_CHANNEL,"Good Evening, " + llKey2Name(llDetectedKey(0)));
    }
}</syntaxhighlight>
|helpers=
=== Helper Functions ===
* [[Stamp2UnixInt]] - List format to Unix timestamp. ex: [2009, 2, 13, 3, 31, 30] to 1234567890
** compatible with '''''llParseString2List( llGetTimestamp(), ["-", "T", ":", "."], [] )'''''
* [[Stamp2WeekdayStr]] - Weekday from (Y, M, D) ex: "Friday" from (2009, 2, 13)
* [[Millisec]] - Converts a timestamp string to integer milliseconds accurate to within a month.
* [[Unix2PST_PDT]] - Converts a Unix Time stamp to an SLT date/time string with PST or PDT indication as appropriate.
* [[Unix2GMTorBST]] - Converts a Unix Time stamp to a UK date/time string with GMT or BST indication as appropriate.
|also_functions=
{{LSL DefineRow||[[llGetDate]]|Same format but without the time.}}
{{LSL DefineRow||[[llGetUnixTime]]|Time in seconds since the epoch.}}
{{LSL DefineRow||[[llGetTime]]|Elapsed script-time.}}
|also_events
|also_events
|also_tests
|also_tests
|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]|}}
{{LSL DefineRow||{{Wikipedia|ISO 8601}}|}}
{{LSL DefineRow||[[Code Racer]]|}} - useful benchmarks within 100 trials
{{LSL DefineRow||[[Efficiency Tester]]|}} - more accurate benchmarks within 10,000 trials
{{LSL DefineRow||[[LSL_Script_Efficiency]]|}} - in-depth discussion of the Efficiency Tester
|notes
|notes
|haiku={{Haiku|As time ticks away,|Tic-tac, tic-tac, on the clock,|No script ever stops.}}
|cat1=Time
|cat1=Time
|cat2
|cat2

Latest revision as of 11:06, 5 September 2023

Summary

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

Returns a string that is the current date and time in the UTC time zone in the format "YYYY-MM-DDThh:mm:ss.ff..fZ"

Appears to be accurate to milliseconds.

Examples

// Reset tracker

string BOOT_TIME;

default
{
    state_entry()
    {
        BOOT_TIME = llGetTimestamp(); // state_entry is triggered on script reset.
    }
    
    touch_start(integer num)
    {
        llSay(PUBLIC_CHANNEL, "The last script was last reset @ " + BOOT_TIME);
        llSay(PUBLIC_CHANNEL, "Right now it is " + llGetTimestamp());
    }
}
// Greeting

default
{
    state_entry()
    {
        llSetTouchText("Greet");
    }
    touch_start(integer num)
    {
        list TimeStamp = llParseString2List(llGetTimestamp(),["-",":"],["T"]); //Get timestamp and split into parts in a list
        integer Hour = llList2Integer(TimeStamp,4);
        if(Hour<12)		
            llSay(PUBLIC_CHANNEL,"Good Morning, Oliver Sintim-Aboagye!");	
        else if(Hour<17)
            llSay(PUBLIC_CHANNEL,"Good Afternoon, " + llDetectedName(0));		
        else
            llSay(PUBLIC_CHANNEL,"Good Evening, " + llKey2Name(llDetectedKey(0)));
    }
}

Useful Snippets

Helper Functions

  • Stamp2UnixInt - List format to Unix timestamp. ex: [2009, 2, 13, 3, 31, 30] to 1234567890
    • compatible with llParseString2List( llGetTimestamp(), ["-", "T", ":", "."], [] )
  • Stamp2WeekdayStr - Weekday from (Y, M, D) ex: "Friday" from (2009, 2, 13)
  • Millisec - Converts a timestamp string to integer milliseconds accurate to within a month.
  • Unix2PST_PDT - Converts a Unix Time stamp to an SLT date/time string with PST or PDT indication as appropriate.
  • Unix2GMTorBST - Converts a Unix Time stamp to a UK date/time string with GMT or BST indication as appropriate.

See Also

Functions

•  llGetDate Same format but without the time.
•  llGetUnixTime Time in seconds since the epoch.
•  llGetTime Elapsed script-time.

Articles

•  ISO 8601
•  "Wikipedia logo"ISO 8601
•  Code Racer - useful benchmarks within 100 trials
•  Efficiency Tester - more accurate benchmarks within 10,000 trials
•  LSL_Script_Efficiency - in-depth discussion of the Efficiency Tester

Deep Notes

Signature

function string llGetTimestamp();

Haiku

As time ticks away,
Tic-tac, tic-tac, on the clock,
No script ever stops.