Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Email Timestamp to human time

Chaz Longstaff
Registered User
Join date: 11 Oct 2006
Posts: 685
06-21-2008 16:57
The email event returns a timestamp that looks like this:

1214092041

Does anyone know off the top of his/her head where there is a function to return in a normal format? (e.g. date / time -- don't care if time is 24 hour or American format.)
_____________________
Thread attempting to compile a list of which animations are freebies, and which are not:

http://forums.secondlife.com/showthread.php?t=265609
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
06-21-2008 22:52
From: LSL Wiki

time is a UNIX timestamp (integer) typecast as a string, similar to that returned by llGetUNIXTime.


You could use an external utility to convert to a human-readable date/time, or calculate the date in LSL (I believe UNIX time ignores leap seconds, so that means you only have to deal with leap years and the normal calendar). That or you could compare the results of llGetUNIXTime() and a more readable function like llGetDate() or llGetTimestamp() and use that to do a conversion.

http://www.lslwiki.net/lslwiki/wakka.php?wakka=email
http://www.lslwiki.net/lslwiki/wakka.php?wakka=llGetUNIXTime
http://www.lslwiki.net/lslwiki/wakka.php?wakka=time
Chaz Longstaff
Registered User
Join date: 11 Oct 2006
Posts: 685
06-23-2008 18:30
>> You could use an external utility

wanted to do it in an LSL script. Recording the time from an email event paramater was just a "nice to have", so it seemed easier to just get it and record it myself in a normal format in the email body, so I have done that.

From: Hewee Zetkin
You could use an external utility to convert to a human-readable date/time, or calculate the date in LSL (I believe UNIX time ignores leap seconds, so that means you only have to deal with leap years and the normal calendar). That or you could compare the results of llGetUNIXTime() and a more readable function like llGetDate() or llGetTimestamp() and use that to do a conversion.

http://www.lslwiki.net/lslwiki/wakka.php?wakka=email
http://www.lslwiki.net/lslwiki/wakka.php?wakka=llGetUNIXTime
http://www.lslwiki.net/lslwiki/wakka.php?wakka=time
_____________________
Thread attempting to compile a list of which animations are freebies, and which are not:

http://forums.secondlife.com/showthread.php?t=265609
Viktoria Dovgal
Join date: 29 Jul 2007
Posts: 3,593
06-23-2008 18:36
From: Chaz Longstaff
wanted to do it in an LSL script.

It might be JIRA time then. The localtime/gmtime stuff would be kind of hairy to do in LSL, looping through to find all the leap years and all that fun.
_____________________
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
06-24-2008 11:39
It's not THAT bad. I believe this should do it.

CODE

list MONTHS = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];

// Assumes we are in the 1970 to 2099 year range, since it doesn't account for
// leap years on the century (but note that 2000 is fine since it is divisible
// by 400.
//
// Returns: [ YYYY MM DD hh mm ss ] (all elements integers)
list unixToDateTime(integer unixTime)
{
integer time = unixTime%86400;
integer hour = time/3600;
integer min = (time%3600)/60;
integer sec = time%60;

integer day = unixTime/86400;

integer year = 1970+4*(day/1461);
day %= 1461;

if (day == 789)
{
// Leap day!
return [ (year+2), 2, 29, hour, min, sec ];
} else if (day > 789)
{
day -= 1;
}

year += day/365;
day %= 365;

integer month;
for (month = 1; month <= 12; ++month)
{
integer monthDays = llList2Integer(MONTHS, month-1);
if (day < monthDays)
{
return [ year, month, (day+1), hour, min, sec ];
}
day -= monthDays;
}

// Should never get here
return [];
}

// Test harness
default
{
state_entry()
{
integer now = llGetUnixTime();
string timestamp = llGetTimestamp();

string result = llList2CSV(unixToDateTime(now));

llOwnerSay("Timestamp: "+timestamp);
llOwnerSay("Result: "+result);
}
}
Chaz Longstaff
Registered User
Join date: 11 Oct 2006
Posts: 685
06-24-2008 12:10
From: Hewee Zetkin
It's not THAT bad. I believe this should do it.
list MONTHS = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];


ah cheers, I'll give it a go and see if I have enough memory for it. Thank you very much.
_____________________
Thread attempting to compile a list of which animations are freebies, and which are not:

http://forums.secondlife.com/showthread.php?t=265609