Difference between revisions of "TimeAgo"

From Second Life Wiki
Jump to navigation Jump to search
(Created page with '{{LSL_Function |func=TimeAgo |mode=user |p1_type=integer|p1_name=tm|p1_desc=Unix Time used for difference |return_type=string |return_text=that will give you the difference in ti...')
 
Line 6: Line 6:
|return_text=that will give you the difference in time.
|return_text=that will give you the difference in time.
|func_footnote=
|func_footnote=
See also: [[String]]
See also: [[llGetUnixTime]]
|spec=<lsl>
|spec=<lsl>
string TimeAgo(integer tm) {
string TimeAgo(integer tm) {

Revision as of 20:27, 23 May 2010

Summary

Function: string TimeAgo( integer tm );

Returns a string that will give you the difference in time.

• integer tm Unix Time used for difference

See also: llGetUnixTime

Specification

<lsl> string TimeAgo(integer tm) {

   integer dif = llGetUnixTime()-tm;
   list pds = ["second","minute","hour","day","week","month","year","decade"];
   list lngh = [1,60,3600,86400,604800,2630880,31570560,315705600];
   integer v;integer no;
   for(v = llGetListLength(lngh)-1; (v >= 0)&&(no = dif/llList2Integer(lngh,v)<=1); v--);

string dd = llList2String(pds,v); integer ntime = dif / llList2Integer(lngh,llListFindList(pds, [dd])); if(no != 1)dd +="s"; dd = (string)ntime + " "+ dd;

   return dd;

} </lsl>

Examples

<lsl> default {

   touch_start(integer total_number)
   {
       integer time = llGetUnixTime() - 180;
       llSay(0,  timeago(time) + " ago");
       }

}


//integer time is the current unix time minus 180 seconds (3 minutes)

//The outcome will be "3 minutes ago"</lsl>