Author Sticky: Post Working Scripts Here
Old Man Coyote Posted: Thursday, 27 June 10:36PM
Function: int SecondsSinceYearZero()

Returns: raw "in game" seconds since Month 1/Day 1/Year 0. Useful for time stamps and for having to do time-math (for Resting scripts, etc.) Yes, the resulting integer will be rather large.

NWScript:
int SecondsSinceYearZero()

{

    object oModule = GetModule();

    int nYear = GetCalendarYear();

    int nMonth = GetCalendarMonth();

    int nDay = GetCalendarDay();

    int nHour = GetTimeHour();

    int nMinute = GetTimeMinute();

    int nSecond = GetTimeSecond();

    int nMilli = GetTimeMillisecond();

    float fSecsPerHour = HoursToSeconds(1);

    float fMinAndSecFactor = 3600/fSecsPerHour;

    float fRLSecond = (IntToFloat(nMinute) * 60.0) + IntToFloat(nSecond) + (IntToFloat(nMilli) / 1000);

    int nICRawSecond = FloatToInt(fRLSecond*fMinAndSecFactor);

    // still have yet to add the year, month, day, and hour.

    // A NWN year has 12 months, a NWN month has 28 days, a NWN day has 24 hours, so:

    // hour = 3600 seconds, day = 86400 seconds, month = 2419200 seconds, year = 29030400 seconds

    int nSecondsSinceYearZero = nICRawSecond + (nHour * 3600) + (nDay * 86400) + (nMonth * 2419200) + (nYear * 29030400);

    return nSecondsSinceYearZero;

}