0Pricing
Lua Academy · Lesson

os.time and os.date

Get the current time.

Why Time Matters

Programs often need to know the current time. A game records when you scored, a log file stamps each event, and a reminder app counts down to a deadline.

Lua keeps its time tools in the built-in os library. The two stars are os.time and os.date. In this lesson you will meet both.

os.time Returns a Number

os.time() with no arguments returns the current moment as a single number.

That number is the count of seconds since a fixed point in the past (the epoch). It is just an integer, so you can store it, compare it, or do math with it.

local now = os.time()
print(now)
print(type(now))

All lessons in this course

  1. os.time and os.date
  2. Formatting Dates
  3. Time Arithmetic
  4. Measuring Durations
← Back to Lua Academy