Websites Navigation: Airbit | Shop | m-shell.net
Languages: EN | DE

Module time: Time and Date Functions

This module provides access to the real time clock. A given point in time in m is always measured as the number of seconds since the beginning of year 0 (assuming the Gregorian calendar).

time.dayofweek

• function dayofweek(secs=time.get()) → Number

Gets the day of the week of the point in time defined by secs, according to the following table:

0Monday
1Tuesday
2Wednesday
3Thursday
4Friday
5Saturday
6Sunday

print time.dayofweek()
→ 0
print time.dayofweek(time.num('2005-05-13'))
→ 4

time.get

• function get() → Number

Gets the local time in seconds since 0000-01-01 00:00:00. The numeric resolution is down to microseconds, but the actual resolution may be be coarser.

print time.get()
→ 63279080895
print str(time.get(), 1, 4)
→ 63279080895.9844

See also: .date

time.set

• function set(secs) → null

Sets the local time in seconds since 0000-01-01 00:00:00 to secs.

time.set(time.get() + 60*60) // advance by 1 hour

time.num

• function num(text, format="YMDhmst") → Number

Converts the string text into seconds since 0000-01-01 00:00:00, according to the format format.

The format string defines the order of the date and time parts in text. Each part finishes if either a character which is not a digit is encountered, or if the part's maximum length is reached. The parts are denoted by the following characters:

CharacterMax. lengthMeaning
Y4Year.
M2Month.
D2Day.
h2Hour (24 hour representation).
m2Minute.
s2Second.
t3Fraction of a second.

One and two digit years are assumed to be in the 21st century, i.e. 2000 is added to them.

Throws ErrArgument if format contains a character other than those above.

print time.get(), time.num(date())
→ 63279080895 63279080895
t=time.num("05-03-27")-40*24*3600;
print time.str(t)
→ 2005-02-15 00:00:00
t=time.num('19:14:18.5', 'hmst')+124.7
print time.str(t,'hh:mm:ss:ttt')
→ 19:16:23.200

See also: time.str

time.str

• function str(secs, format="YYYY-MM-DD hh:mm:ss") → String

Converts the seconds since 0000-01-01 00:00:00 secs into a string, according to the format format.

Each character in the format string will be converted into a character in the resulting string, according to the following table:

YNext digit of year
MNext digit of month
DNext digit of day
hNext digit of hour
mNext digit of minute
sNext digit of second
tNext digit of fractions of second

The format is converted from right to left, except for t.

print date(), time.str(time.get())
→ 2005-03-14 18:28:15 2005-03-14 18:28:15
print time.str(time.get(), "hh:mm:ss.ttt")
→ 18:28:15.424
print time.str(time.get(), "DD.MM.YY")
→ 14.03.05

See also: time.num, .date

time.utc

• function utc() → Number

Gets the real time in the UTC (Universal Time Coordinate) time zone. This equals Greenwich local time, excluding any shift by daylight saving time.

The difference between local time and UTC time is the local time zone:

print time.get() - time.utc()
→ 3600

time.weekofyear

• function weekofyear(secs=time.get()) → Number

Gets the week of the year of the point in time defined by secs. The first week in the year is the first week having four or more days in the year defined by secs.

print time.weekofyear()
→ 11
print time.weekofyear(time.num('2005-01-01'))
→ 53


© 2004-2011 airbit AG, CH-8008 Zürich
Document AB-M-LIB-888
mShell Home  > Documentation  > Manuals