I was looking for a time and date script to use for reference and to learn from. I found this one but I dont quite understand how to call the time and date in the actual script default state. Could someone please fill me in a bit so I understand. Thanks
Code
// Take a timestamp and return it in PST string format
// Example of the output format is "Sun 7/15/2007 1:02 pm"
string timestamp2PST(string timestamp) {
// Set up constants required for the function (could be made global)
list weekday_names = [ "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" ];
list days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
// Parse the timestamp
list parts = llParseString2List(timestamp, ["-", "T", ":", ".", "Z"], []);
// If it's not a timestamp, then just return the original string
if (llGetListLength(parts) != 7) {
return timestamp;
} else {
// Set up the local variables we need
integer year = llList2Integer(parts, 0);
integer month = llList2Integer(parts, 1);
integer day = llList2Integer(parts, 2);
integer hour = llList2Integer(parts, 3);
integer minute = llList2Integer(parts, 4);
integer second = llList2Integer(parts, 5);
// Account for time difference from simulator to UTC->PST
integer difference = (integer)((llGetWallclock() - llGetGMTclock()) / 3600);
if (difference > 0) {
difference -=24;
}
hour += difference;
// Deal with day/month/year boundaries crossed by the adjustment for the time difference
if (hour < 0) {
day--;
hour += 24;
if (day <= 0) {
month--;
if (month <= 0) {
year--;
month += 12;
}
day = llList2Integer(days_in_month, month - 1);
// Do a leap year adjustment if required
if (month == 2 && year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) {
day++;
}
}
}
// Determine the day of the week
// This highly non-intuitive code is based on an algorithm
// from http://mathforum.org/library/drmath/view/55837.html
if (month < 3) {
month += 12;
--year;
}
integer weekday_number = (day + 2 * month + (3 * (month + 1)) / 5
+ year + year / 4 - year / 100 + year / 400 + 2) % 7;
if (month > 12) {
month -= 12;
++year;
}
// Build the PST date string (fixed format)
string date = llGetSubString(llList2String(weekday_names, weekday_number), 0, 2);
date += " " + (string)month + "/" + (string)day + "/" + (string)year;
// Convert the hour to am/pm
string suffix = " pm";
if (hour < 12) {
suffix = " am";
if (hour == 0) {
hour = 12;
}
} else if (hour > 12) {
hour %= 12;
}
date += " " + (string)hour + ":";
if (minute < 10) {
date += "0" + (string)minute;
} else {
date += (string)minute;
}
date += suffix;
return date;
}
}