Join us in Outworldz at www.outworldz.com:9000 or follow us:

Search dozens of selected web sites for OpenSim and LSL script

New! Script Meta-Search will search thousands of scripts here and at other sites for LSL or Opensim scripts.
Loading

Want to add a script or a project? Upload it and a half million people will see it and your name here this year.

Home   Show All
Category: Contributor: Creator
Clock Millisecond_Time  

Millisecond_Time

A collection of time utility functions, to try and make sub-second and timezone handling easier.

First a timezone-aware cousin of llGetGMTclock:

Category: Clock
By : Minsk Oud
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

the Zip file

Download all files for Millisecond_Time
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Millisecond_Time_1.lsl
Get file # 2. Millisecond_Time_2.lsl
1 // By Christopher Wolfe (SL name "Minsk Oud").
2 // This script is in the public domain.
3
4 //
5 // A version of llGetGMTclock() with timezone support, using the
6 // offset in seconds. Some useful offsets:
7 //
8 // EST = -5 * 3600 = -18000
9 // PST = -8 * 3600 = -28800
10 //
11 integer GetTZclock(integer offset)
12 {
13 if(offset < 0) offset += 86400;
14 integer time = (integer) llGetGMTclock() + offset;
15 if(time >= 86400) time -= 86400;
16 return time;
17 }

Millisecond_Time

The remainder of these functions deal with time of day as *milliseconds* since midnight. As this format would overflow every ~24 days, it must not be used to represent date or elapsed time information (unless you are Microsoft and like your servers crashing).

Category: Clock
By : Minsk Oud
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

1 // By Christopher Wolfe (SL name "Minsk Oud").
2 // This script is in the public domain.
3
4 // Gets the number of milliseconds since midnight UTC.
5 integer GetGMTmsclock()
6 {
7 string stamp = llGetTimestamp();
8 return
9 (integer) llGetSubString(stamp, 11, 12) * 3600000 +
10 (integer) llGetSubString(stamp, 14, 15) * 60000 +
11 llRound((float) llGetSubString(stamp, 17, -2) * 1000.0);
12 }
13
14 // Gets the number of milliseconds since midnight in the specified
15 // timezone, using the offset in milliseconds. Some useful offsets:
16 //
17 // EST = -5 * 3600000 = -18000000
18 // PST = -8 * 3600000 = -28800000
19 //
20 integer GetTZmsclock(integer offset)
21 {
22 if(offset < 0) offset += 86400000;
23 integer time = (integer) GetGMTmsclock() + offset;
24 if(time >= 86400000) time -= 86400000;
25 return time;
26 }
27
28 //
29 // Formats a number of milliseconds since midnight as human readable
30 // time of day.
31 //
32 // time: Number of milliseconds since midnight. Must be greater than
33 // or equal to zero and strictly less than 86400000.
34 //
35 // military: If TRUE, output in 24-hour (or military) time.
36 // If FALSE, output in 12-hour time with AM/PM indicator.
37 //
38 // second_decimals: Number of decimal digits to display for seconds.
39 // Zero will remove the decimal point, greater than three
40 // is useless.
41 //
42 string FormatTime(integer time, integer military, integer second_decimals)
43 {
44 // Uncomment this to ensure time is within the correct range
45 //
46 // while(time < 0) time += 86400000;
47 // while(time >= 86400000) time -= 86400000;
48 //
49
50 integer hour = time / 3600000; time -= hour * 3600000;
51 integer minute = time / 60000; time -= minute * 60000;
52 integer second = time / 1000; time -= second * 1000;
53
54 string ampm;
55 if(military) {
56 ampm = "";
57 }
58 else {
59 // 12 noon until 11:59:59 (just before midnight) are "PM"
60 if(hour >= 12) ampm = " PM";
61 // 12 midnight until 11:59:59 (just before noon) are "AM"
62 else ampm = " AM";
63
64 if(hour == 0) hour = 12;
65 else if(hour > 12) hour -= 12;
66 }
67
68 // Only pad the hour field if military time is specified
69
70 string shour;
71 if(military && hour < 10) shour = "0" + (string) hour; else shour = (string) hour;
72
73 // Pad the minute and second fields in either time format
74
75 string sminute;
76 if(minute < 10) sminute = "0" + (string) minute; else sminute = (string) minute;
77
78 string ssecond;
79 if(second < 10) ssecond = "0" + (string) second; else ssecond = (string) second;
80
81 string decimals;
82 if(second_decimals > 0) {
83 // Construct the decimals string with all interesting digits to the
84 // left of the decimal point. This automatically provides zero padding
85 // unless the actual decimal value is zero.
86 decimals = (string) llFloor(time * llPow(10, second_decimals - 3));
87
88 // If the decimal value was exactly zero, additional padding will need
89 // to be added.
90 while(llStringLength(decimals) < second_decimals) decimals += "0";
91
92 // Prepend a decimal point.
93 decimals = "." + decimals;
94 }
95 else {
96 decimals = "";
97 }
98
99 return shour + ":" + sminute + ":" + ssecond + decimals + ampm;
100 }

Back to the Best Free Tools in Second Life and OpenSim.