Don't click here unless you want to be banned.

LSL Wiki : LibraryTimeDateFunctions

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are crawl338.us.archive.org

Library Time & Date Functions


This is a list of useful functions for retrieving information about the current Time & Date.

See the comments above each function for usage.

////////////////////////////////////////////////////////////////////////////
//           GarrMe Dagger's Time & Date Functions v.10.13.07             //
//                    Copyright (c) 2007 Mark Timlin                      //
////////////////////////////////////////////////////////////////////////////
//                                                                        //
//  This program is free software: you can redistribute it and/or modify  //
//  it under the terms of the GNU General Public License as published by  //
//  the Free Software Foundation version 3 of the License.                //
//                                                                        //
//  This program is distributed in the hope that it will be useful,       //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of        //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     //
//  General Public License for more details - http://www.gnu.org/licenses //
//                                                                        //
////////////////////////////////////////////////////////////////////////////

// Returns the current millisecond.
integer TimeMillisecond()
{
    list time = llParseString2List(llGetTimestamp(), ["."], []);
    llOwnerSay(llGetTimestamp());
    return (integer)llGetSubString(llList2String(time, 1), 0, 1);
}

// Returns the current seconds.
integer TimeSecond()
{
    list time = llParseString2List(llGetTimestamp(), ["T",":","Z"], []);
    return llList2Integer(time, 3);
}

// Returns the current minutes.
integer TimeMinute()
{
    list time = llParseString2List(llGetTimestamp(), ["T",":","Z"], []);
    return llList2Integer(time, 2);
}

// Returns the current hour (in military time).
integer TimeHour()
{
    list time = llParseString2List(llGetTimestamp(), ["T",":","Z"], []);
    return llList2Integer(time, 1);
}

// Returns the time for a specific hour, minute, and second in the format HH:MM:SS AM/PM.
string TimeSerial(integer hour, integer minute, integer second)
{
    string AMPM = "AM";
    string min = (string)minute;
    string sec = (string)second;
    if (hour > 12)
    {
        AMPM = "PM";
        hour -= 12;
    }
    if (minute < 10) min = "0" + min;
    if (second < 10) sec = "0" + sec; 
    return (string)hour + ":" + min + ":" + sec + " " + AMPM;
}

// Returns the current day.
integer DateDay()
{
    list time = llParseString2List(llGetTimestamp(), ["-", "T"], []);
    return (integer)llList2Float(time, 2);
}

// Returns the current month.
integer DateMonth()
{
    list time = llParseString2List(llGetTimestamp(), ["-", "T"], []);
    return (integer)llList2Float(time, 1);
}

// Returns the current year.
integer DateYear()
{
    list time = llParseString2List(llGetTimestamp(), ["-", "T"], []);
    return (integer)llList2Float(time, 0);
}

// Returns the name of a specified month.  If abbreviate is TRUE only the 1st 3 letters of
// the month will be returned.
string DateMonthName(integer month, integer abbreviate)
{
    list name = ["January", "February", "March", "April", "May", "June", "July", "August",
        "September", "November", "December"];
    string str = llGetSubString(llList2String(name, month - 1), 0, -1);
    if (abbreviate)
        str = llGetSubString(str, 0, 2);    
    return str;    
}

// Returns the name of the day of the week for a given date.  If abbreviate is TRUE
// only the 1st 3 letters of the day will be returned.
// * Uses Christian Zeller's congruence algorithm to calculate the day of the week.
string DateDayName(integer month, integer day, integer year, integer abbreviate)
{
    list name = ["Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"];
    if (month < 3)
    {
        month += 12;
        year -= 1;
    }
    integer index = (day + 2*month + (3*(month + 1))/5 + year + year/4 - year/100 + year/400 + 2) % 7;
    string str = llGetSubString(llList2String(name, index), 0, -1);
    if (abbreviate)
        str = llGetSubString(str, 0, 2);    
    return str;
}

default
{
    state_entry()
    {
        // Example usage of these functions
        llOwnerSay("Today is: " + DateDayName(DateMonth(), DateDay(), DateYear(), FALSE) + " " +
            DateMonthName(DateMonth(), FALSE) + " " + (string)DateDay() + ", " + (string)DateYear() +
            " and the time is: " + TimeSerial(TimeHour(), TimeMinute(), TimeSecond()));
    }
}
There is one comment on this page. [Display comments/form]