string llGetDate()
Returns the current
UTC date as
YYYY-MM-DD (with padding zeros).
See also
llGetTimestamp.
Example
This function returns the current date in
PST. It works just like the
llGetDate function by returning a
string of the PST date in
YYYY-MM-DD format, so once this is added to a script, it can be used instead of
llGetDate. (Note: this does not observe Daylight Savings Time. For a script that does that, see
this forum thread.) <-This note is wrong, since llGetWallclock observes DST this script will correctly observe DST.
string GetPSTDate()
{
string DateToday = "";
string DateUTC = llGetDate();
if (llGetGMTclock() - llGetWallclock() < 0) //if it's negative then the date has changed.
{
integer year = (integer)llGetSubString(DateUTC, 0, 3);
integer month = (integer)llGetSubString(DateUTC, 5, 6);
integer day = (integer)llGetSubString(DateUTC, 8, 9);
if (day == 1) // if day is the 1st of a month, fix the date
{
if (month == 1) // if it is January
{
year = year - 1; // wind back the year
month = 12; // set the month to December
day = 31; // set to last day of December
}
else
{
month = month - 1; // wind back one month
if(month == 2)
day = 28 + !(year % 4) - !(year % 100) + !(year % 400);
else
day = 31 - (month == 4 || month == 6 || month == 9 || month == 11);
}
}
else
day = day - 1;
if(month < 10)
DateToday = "0";
DateToday+=(string)month + "-";
if(day < 10)
DateToday += "0";
DateToday+=(string)day;
return (string)year + "-" + DateToday;
}
return DateUTC;
}
// Function to calculate the numeric day of year
integer dayOfYear(integer year, integer month, integer day)
{
return
day
+ (month - 1) * 30 - (2 - ((year % 4) == 0) * ((year % 100) != 0)) * (month > 2)
+ (month / 2) * (month <= 8) + (4 + (month - 7) / 2) * (month > 8);
}
default
{
touch_end(integer count)
{
list dateComponents = llParseString2List(llGetDate(), ["-"], []);
integer year = (integer) llList2String(dateComponents, 0);
integer month = (integer) llList2String(dateComponents, 1);
integer day = (integer) llList2String(dateComponents, 2);
llSay(0, "The current day of the year is " + dayOfYear(year, month, day));
}
}
This article wasn't helpful for you? Maybe the
related article at the LSL Portal is able to bring enlightenment.
Functions |
Time |
Simulator