sys.Datetime([moment]) constructor

The Datetime constructor returns a Datetime value representing a moment, including a date part and a time part.
The Datetime value is initialized with the moment argument. If that argument is omitted, the constructor returns the current local date and time. The Datetime value can then be accessed, modified, converted to string,...

The format string depends on the current user locale, using the standard short format.
For example, for the date part, the constructor use mm/dd/yyyy for English but dd/mm/yyyy for French locale

Please note that using the Datetime constructor, the maximum allowed value for the year is 9999. If needed, you can change the year to a higher value with an assignment to the year property (which allows a maximum value of 30827)

Parameters

moment

An optional string used to specify the Datetime value, using the current short date format depending on the user current locale.

Example

local console = require "console" -- get current date and time local today = sys.Datetime() -- get the year of birth from the user console.write("Enter your year of birth : ") local yearofbirth = tonumber(console.readln()) -- ouputs the age of the user print("You are "..tonumber(today.year-yearofbirth).." old")