CaseyRedDragon Wise Posted July 20, 2012 Share Posted July 20, 2012 This script will tell the time in AM/PM time or 24 hour time for ether of the four USA Time Zones and also tells the date and what day of the week it is. I was going to put this on the wiki but I couldn't figure it out.// Time Script by CaseyRedDragon Wise // feel free to IM me if you have any questions or comments integer dateoff; string smin; string sseconds; string timeofday; string time; //Set timezone to the number corresponding to the time zone you want //Pacific Time Zone = 0 //Mountain Time Zone = 1 //Central Time Zone = 2 //Eastern Time Zone = 3 integer timezone = 3; //Set type to "standard" for AM/PM Time or set to "military" for Military Time string type = "standard"; string uStamp2WeekdayStr( integer vIntYear, integer vIntMonth, integer vIntDay ){ return llList2String ( ["Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday"], (vIntYear + (vIntYear >> 2) - ((vIntMonth < 3) & !(vIntYear & 3)) + vIntDay + (integer)llGetSubString( "_033614625035", vIntMonth, vIntMonth )) % 7 ); } default { state_entry() { llSetTimerEvent(1.0); } timer() { integer seconds = llFloor(llGetWallclock()); //llSay(0, (string)seconds); integer min = llFloor(seconds/60); seconds = seconds - (min*60); integer hour = llFloor(min/60); min = min - (hour*60); hour = hour + timezone; if(hour >= 24) {hour = hour - 24;} integer mili = hour; if(hour < 12) {timeofday = "AM";} else {timeofday = "PM";} if(hour > 12) {hour = hour - 12;} if(hour == 0) {hour = 12;} string shour = (string)hour; if(min < 10) {smin = "0"+(string)min;} else { smin = (string)min;} if(seconds < 10) { sseconds = "0"+(string)seconds;} else {sseconds = (string)seconds;} if(type == "standard") { time = shour + ":" + smin + ":" + sseconds + " " + timeofday; } if(type == "military") { time = (string)mili + ":" + smin + ":" + sseconds; } list timepart = llParseString2List(llGetTimestamp(), ["T", ":"], []); integer uhour = (integer)llList2String(timepart, 1); if(uhour < 12 && mili > 12) { // -1 day dateoff = 1; } else { dateoff = 0; } list dateComponents = llParseString2List(llGetDate(), ["-"], []); integer year = (integer)llList2String(dateComponents, 0); integer month = (integer)llList2String(dateComponents, 1); integer day = (integer)llList2String(dateComponents, 2); day = day - dateoff; string date = uStamp2WeekdayStr(year, month, day) + " " + (string)month + "-" + (string)day + "-" + (string)year; string datetime = time + "\n" + date; llSetText(datetime, ZERO_VECTOR, 1.0); } } 1 Link to comment Share on other sites More sharing options...
Rolig Loon Posted July 20, 2012 Share Posted July 20, 2012 Nice work. For completeness, don't forget Hawaiian Standard Time (HST) and Alaskan Standard Time (AKST) too. :smileywink: Link to comment Share on other sites More sharing options...
CaseyRedDragon Wise Posted July 20, 2012 Author Share Posted July 20, 2012 well it seems alot just to find the time. I think there needs to be a Function that will make this easy and simpler to do. Link to comment Share on other sites More sharing options...
Rolig Loon Posted July 20, 2012 Share Posted July 20, 2012 You've already done the work, though. How much harder is it to add two more time zones, each just an extra hour offset from the one to the east of it? The hardest parts of your script are the Void's weekday function, which you are using to good effect here, and gettting the day to roll over properly at midnight. Link to comment Share on other sites More sharing options...
CaseyRedDragon Wise Posted July 21, 2012 Author Share Posted July 21, 2012 Well see it gets the time for the 4 time zones from the llGetWallclock which will adjust for DST, but Hawaiian and Alaskan don't have DST so I would have to make the script be able to know when DST is and then adjust for it which would be long. There is a small bug in the script, sometimes on the last day of the month instead of saying 7-31-2012 it mite say 8-0-2012. Link to comment Share on other sites More sharing options...
Rolig Loon Posted July 21, 2012 Share Posted July 21, 2012 Ah, I see... So use llGetGMTClock instead. Link to comment Share on other sites More sharing options...
CaseyRedDragon Wise Posted July 21, 2012 Author Share Posted July 21, 2012 i'll get to it but its free for anyone to do it themself if they want Link to comment Share on other sites More sharing options...
KS Moonites Posted May 25, 2013 Share Posted May 25, 2013 really awesome! Link to comment Share on other sites More sharing options...
Recommended Posts
Please take a moment to consider if this thread is worth bumping.
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now