User:Trinity Coulter/Using HTTPRequest to Convert GMT to Unix time

From Second Life Wiki
Jump to: navigation, search

Neat little script to help with an overly complicated task in regular LSL.

<lsl> string myGMTTime; default {

   state_entry()
   {
       llSay(0,"Touch to convert GMT to Unix time");
   }
   
   touch_start(integer total_number)
   {
       myGMTTime = llGetTimestamp();
       
       string toUnix = "http://www.iwebtool.com/tool/tools/unix_time_converter/unix_time_converter.php?year=" + llGetSubString(myGMTTime,0,3) + "&mon=" + llGetSubString(myGMTTime,5,6) + "&day=" + llGetSubString(myGMTTime,8,9) + "&hour=" + llGetSubString(myGMTTime,11,12) + "&min=" + llGetSubString(myGMTTime,14,15) + "&sec=" + llGetSubString(myGMTTime,17,18);
       llHTTPRequest(toUnix,[HTTP_METHOD,"GET"],"");
   }
   
    http_response(key request_id,integer status, list metadata, string body)
   {
       body = llGetSubString(body, 50, -9);
       //corrects HTTP response from server's Eastern to UTC
       integer timecorrect = (integer)body - 18000;
       llSay(0,myGMTTime + " converts to " + (string)timecorrect);
   }

} </lsl>