Time Arithmetic
Add and compare times.
Time Is Just Numbers
Because os.time returns plain seconds, doing date math is mostly ordinary arithmetic. Add seconds to move forward, subtract to look back.
This lesson shows how to shift times, compare them, and find the gap between two moments.
Seconds in a Minute, Hour, Day
To work in larger units, remember the basic counts: 60 seconds in a minute, 3600 in an hour, and 86400 in a day.
Multiplying by these constants lets you express any duration in seconds.
print("Minute:", 60)
print("Hour:", 60 * 60)
print("Day:", 24 * 60 * 60)All lessons in this course
- os.time and os.date
- Formatting Dates
- Time Arithmetic
- Measuring Durations