Difference between revisions of "TimeAPI Clock Script"

From Second Life Wiki
Jump to navigation Jump to search
(adding part)
m (<lsl> tag to <source>)
Line 4: Line 4:
== Script ==
== Script ==


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


Line 30: Line 30:
     }
     }
}
}
</lsl>
</source>
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.



Revision as of 19:34, 24 January 2015

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.