To help you out, I'll quote selectively from http://www.lua.org/pil/22.1.html
Quote:
22.1 – Date and Time
Two functions, time and date, do all date and time queries in Lua.
The time function, when called without arguments, returns the current date and time, coded as a number. (In most systems, that number is the number of seconds since some epoch.)
...
The date function, despite its name, is a kind of a reverse of the time function: It converts a number representing the date and time back to some higher-level representation. Its first parameter is a format string, describing the representation we want. The second is the numeric date-time; it defaults to the current date and time.
To produce a date table, we use the format string "*t". For instance, the following code
date_table = os.date("*t", 906000490)
produces the table
{year = 1998, month = 9, day = 16, yday = 259, wday = 4,
hour = 23, min = 48, sec = 10, isdst = false}
...
date tables have the following significant fields:
year a full year
month 01-12
day 01-31
hour 01-31
min 00-59
sec 00-59
isdst a boolean, true if daylight saving
...
Notice that, besides the fields used by os.time, the table created by os.date also gives the week day (wday, 1 is Sunday) and the year day (yday, 1 is January 1).
So you either want to do...
current_time = os.time()
date_table = os.date("*t", current_time)
or more simply, just
date_table = os.date("*t")
which is a shortcut for the former, but the former allows you to save a timestamp for later.
Then, for example, your "currentMonth" would be
currentMonth = date_table.month
You can verify for yourself the output of os.date with the following simple printing code...
for k,v in pairs(os.date("*t")) do
print(k.." , "..tostring(v))
end
|