Current Unix Timestamp SECONDS SINCE JAN 01 1970

Current UTC Time
2025-08-20
Convert Datetime to Unix Timestamp in Lua

How to convert Datetime to Unix timestamp in Lua

🎈 🎈 🎈
+1

    -- Convert Date to Unix timestamp
    local dateTable = {year = 2005, month = 4, day = 14, hour = 14, min = 22, sec = 51}
    local unixTimestamp = os.time(dateTable)
    
    print("Unix Timestamp: " .. unixTimestamp)            
        

Output:
Unix Timestamp: 1113488571
Example only. There may be multiple ways to perform this operation.

Code Explanation

In this example, a table representing the date '2005-04-14 14:22:51' is passed to the os.time function, which converts it to the corresponding Unix timestamp.
The result is the Unix timestamp '1113488571', which is printed. The table keys year, month, day, hour, min, and sec represent the components of the date.



Other useful Lua date functions

Function Description Example
os.date() Returns the formatted date and time as a string. Can take a format string and a Unix timestamp. os.date("%Y-%m-%d %H:%M:%S", 1589530245) returns 2020-05-15 08:10:45
os.time() Returns the current time as a Unix timestamp or converts a table with date components to a Unix timestamp. os.time({year=2020, month=5, day=15, hour=8, min=30, sec=45}) returns 1589530245
os.clock() Returns the CPU time used by the program in seconds. os.clock() returns the CPU time used by the script.
os.difftime() Returns the difference in seconds between two Unix timestamps. os.difftime(1589530245, 1589443845) returns 86400 (1 day).
os.setlocale() Sets the locale for date and time formatting. os.setlocale("en_US.UTF-8") sets the locale to US English.
os.date("*t") Returns the current date and time as a table with keys for the year, month, day, hour, etc. os.date("*t") returns a table representing the current date and time.
os.date("!*t") Returns the UTC date and time as a table with keys for the year, month, day, hour, etc. os.date("!*t") returns a table representing the UTC date and time.
os.time() Returns the current Unix timestamp. os.time() returns the current Unix timestamp.
Current Unix Timestamp SECONDS SINCE JAN 01 1970

Current UTC Time
2025-08-20
Ad Banner Placeholder
Ad Banner Placeholder
Ad Banner Placeholder
Ad Banner Placeholder