LlGetUnixTime: Difference between revisions

From Second Life Wiki
Jump to navigation Jump to search
Strife Onizuka (talk | contribs)
mNo edit summary
Nelson Jenkins (talk | contribs)
expand note on Y2038 problem and add note regarding Lua and LSL/Luau cross-compilation
 
(4 intermediate revisions by 4 users not shown)
Line 5: Line 5:
|func_footnote
|func_footnote
|func_desc
|func_desc
|return_text=that is the number of seconds elapsed since 00:00 hours, Jan 1, 1970 {{Wikipedia|Coordinated Universal Time|UTC}} from the system clock.
|return_text=that is the number of seconds elapsed since 00:00 hours, Jan 1, 1970 {{Wikipedia|Coordinated Universal Time|UTC}} from the system clock ([https://en.wikipedia.org/wiki/Unix_time Unix time]).
|spec
|spec
|caveats
|caveats=
* Time codes outside 1901-12-13 20:45:52 UTC and 2038-01-19 03:14:08 UTC cannot be represented in LSL due to its use of signed 32-bit integers for Unix times. Scripts that rely on this function after January 19, 2038 may have logical errors.
** Consider [[llGetTimestamp]] instead, which will correctly report time through 2038.
** Lua scripts (not including LSL scripts compiled for the Luau VM) do not have this limitation with <code>os.time()</code>, since it returns a 64-bit number and will correctly represent time through the likely heat death of the universe.
|constants
|constants
|examples=<lsl>
|examples=<syntaxhighlight lang="lsl2">
// Reset tracker
// Reset tracker
integer BOOT_TIME;
integer BOOT_TIME;
Line 26: Line 29:
     }
     }
}
}
</lsl>
</syntaxhighlight>
|helpers=
|helpers=
=== Helper Functions: ===
=== Helper Functions: ===
Line 34: Line 37:
{{LSL DefineRow||[[uuLinuxTime]]|Converts date to Unix Time stamp (from Linux kernel's sources)}}
{{LSL DefineRow||[[uuLinuxTime]]|Converts date to Unix Time stamp (from Linux kernel's sources)}}
{{LSL DefineRow||[[Unix2WeekdayStr]]|Gets the weekday from a Unix Time stamp. ex: "Friday" from 1234567890}}
{{LSL DefineRow||[[Unix2WeekdayStr]]|Gets the weekday from a Unix Time stamp. ex: "Friday" from 1234567890}}
{{LSL DefineRow||[[Unix2PST_PDT]]|Converts Unix Time stamp to an SLT date/time string with PST or PDT indication as appropriate}}
{{LSL DefineRow||[[Unix2GMTorBST]]|Converts Unix Time stamp to a UK date/time string with GMT or BST indication as appropriate}}
{{!}}}
{{!}}}
|also_functions=
|also_functions=
Line 45: Line 50:
|permission
|permission
|negative_index
|negative_index
|haiku={{Haiku|Ticking time bomb waits,|A few years till scripts explode—|Y2K, take two!|author=ChatGPT 4}}
|cat1=Time
|cat1=Time
|cat2
|cat2

Latest revision as of 01:38, 20 April 2026

Summary

Function: integer llGetUnixTime( );
0.0 Forced Delay
10.0 Energy

Returns an integer that is the number of seconds elapsed since 00:00 hours, Jan 1, 1970 "Wikipedia logo"UTC from the system clock (Unix time).

Caveats

  • Time codes outside 1901-12-13 20:45:52 UTC and 2038-01-19 03:14:08 UTC cannot be represented in LSL due to its use of signed 32-bit integers for Unix times. Scripts that rely on this function after January 19, 2038 may have logical errors.
    • Consider llGetTimestamp instead, which will correctly report time through 2038.
    • Lua scripts (not including LSL scripts compiled for the Luau VM) do not have this limitation with os.time(), since it returns a 64-bit number and will correctly represent time through the likely heat death of the universe.

Examples

// Reset tracker
integer BOOT_TIME;
default
{
    state_entry()
    {
        BOOT_TIME = llGetUnixTime(); 
        llSetTimerEvent(0.1);
    }
    
    timer()
    {
        llSetText((string)(llGetUnixTime() - BOOT_TIME) + " Seconds since boot.\n\n ", <1,0,0>, 1.0);
        llSetTimerEvent(1);
    }
}

Useful Snippets

Helper Functions:

•  Unix2StampLst Converts Unix Time stamp to a list. ex: 1234567890 to [2009, 2, 13, 23, 31, 30]
•  Stamp2UnixInt Converts date to Unix Time stamp. ex: [2009, 2, 13, 23, 31, 30] to 1234567890
•  uuLinuxTime Converts date to Unix Time stamp (from Linux kernel's sources)
•  Unix2WeekdayStr Gets the weekday from a Unix Time stamp. ex: "Friday" from 1234567890
•  Unix2PST_PDT Converts Unix Time stamp to an SLT date/time string with PST or PDT indication as appropriate
•  Unix2GMTorBST Converts Unix Time stamp to a UK date/time string with GMT or BST indication as appropriate

See Also

Functions

•  llGetTimestamp Human Readable UTC Date and time
•  llGetDate Human Readable UTC Date
•  llGetTime Elapsed script-time.

Deep Notes

Tests

•  llGetUnixTime Conformance Test

Signature

function integer llGetUnixTime();

Haiku

Ticking time bomb waits,
A few years till scripts explode—
Y2K, take two!
— ChatGPT 4