Day of the Week
Revision as of 20:58, 29 January 2007 by DoteDote Edison (talk | contribs)
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Method to get the day of the week from a unix timestamp - llGetUnixTime. The timestamp returns the number of seconds elapsed beginning Thursday, January 1, 1970 UTC. This script first converts the seconds to hours, then adds the GMT offset (if desired), then converts the hours to days, and finally grabs the day of the week from a list.
// Give day of the week // DoteDote Edison list weekdays = ["Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday"]; integer offset = -4; // offset from UTC default { state_entry() { // } touch_start(integer total_number) { integer hours = llGetUnixTime()/3600; integer days = (hours + offset)/24; integer day_of_week = days%7; llSay(0, "Today is " + llList2String(weekdays, day_of_week)); } }
And a function version:
string getDay(integer offset) { list weekdays = ["Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday"]; integer hours = llGetUnixTime()/3600; integer days = (hours + offset)/24; integer day_of_week = days%7; return llList2String(weekdays, day_of_week); } default { touch_start(integer total_number) { integer offset = -4; // offset from UTC llSay(0, "Today is " + getDay(offset) + "."); } }