Difference between revisions of "TimeAPI Clock Script"

From Second Life Wiki
Jump to navigation Jump to search
m
m (Replaced <source> with <syntaxhighlight>; reinforced the note regarding the non-functional API; added category)
 
Line 2: Line 2:
This is a script that I made using LSL's HTTP request function to get the time from the Internet via TimeAPI.com. It gets the time from TimeAPI.com and shows the current time.
This is a script that I made using LSL's HTTP request function to get the time from the Internet via TimeAPI.com. It gets the time from TimeAPI.com and shows the current time.


[Note: timeapi.org seems to have shut down in 2017. However, the principles of this script still illustrate simple HTTP GET usage from LSL.]
{{Note|<code>timeapi.org</code> seems to have shut down in 2017. However, the principles of this script still illustrate simple HTTP GET usage from LSL.}}


== Script ==
== Script ==


<source lang="lsl2">
<syntaxhighlight lang="lsl2">
key reqKey;
key reqKey;


Line 32: Line 32:
     }
     }
}
}
</source>
</syntaxhighlight>
Since llGetWallClock() returns Pacific time and llGetGMTClock() returns UTC and that counts seconds since midnight, this script shows time in UTC, Eastern Time, Central Time, Mountain Time, Pacific Time, Alaska time, Hawaii time, CET, EET or Moscow time.
Since llGetWallClock() returns Pacific time and llGetGMTClock() returns UTC and that counts seconds since midnight, this script shows time in UTC, Eastern Time, Central Time, Mountain Time, Pacific Time, Alaska time, Hawaii time, CET, EET or Moscow time.


You can customize the display of the clock by editing the format. (This requires understanding for Ruby coding) For reference, please see http://apidock.com/ruby/Time/strftime
<s>You can customize the display of the clock by editing the format. (This requires understanding for Ruby coding) For reference, please see http://apidock.com/ruby/Time/strftime


For infomation on TimeAPI, please see http://www.timeapi.org/
For infomation on TimeAPI, please see http://www.timeapi.org/</s>


The HTTP clock script is open-sourced and it is in the public domain. You can contribute to it and use it in your projects.
The HTTP clock script is open-sourced and it is in the public domain. You can contribute to it and use it in your projects.
'''Note:''' If you happened upon this script for the time retrieval API, see the [[Talk:TimeAPI Clock Script|Talk page]] for suggestions regarding alternatives.
[[Category:LSL Examples]]

Latest revision as of 12:07, 29 January 2025

This is a script that I made using LSL's HTTP request function to get the time from the Internet via TimeAPI.com. It gets the time from TimeAPI.com and shows the current time.

NOTE: timeapi.org seems to have shut down in 2017. However, the principles of this script still illustrate simple HTTP GET usage from LSL.

Script

key reqKey;

default
{
    state_entry(){
        llSetTimerEvent(1);
    }
    
    http_response(key req_id, integer status, list metadata, string body)
    {
        if (req_id == reqKey)
        {
            if(status == 200) {
                llSetText(body,<1,1,1>,1.0);
            } else {
                llSetText("ERROR",<1,0,0>,1.0);
            }
        }
    }
    
    timer()
    {
        reqKey = llHTTPRequest("http://www.timeapi.org/utc/now?format=%25H:%25M:%25S", [HTTP_METHOD,"GET"],"");
    }
}

Since llGetWallClock() returns Pacific time and llGetGMTClock() returns UTC and that counts seconds since midnight, this script shows time in UTC, Eastern Time, Central Time, Mountain Time, Pacific Time, Alaska time, Hawaii time, CET, EET or Moscow time.

You can customize the display of the clock by editing the format. (This requires understanding for Ruby coding) For reference, please see http://apidock.com/ruby/Time/strftime

For infomation on TimeAPI, please see http://www.timeapi.org/

The HTTP clock script is open-sourced and it is in the public domain. You can contribute to it and use it in your projects.

Note: If you happened upon this script for the time retrieval API, see the Talk page for suggestions regarding alternatives.