TimeAPI Clock Script

From Second Life Wiki
Jump to: navigation, search

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.

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.