Time Object

Top  Previous  Next

The time object holds a time object able to express times from 0:00 to 23:59.

 

Properties

Methods

Operators

Properties

Name

Type

Description

hour

number

The hour part of the time [0..23]

minute

number

The minute part of time [0..59]

second

number

The second part of time [0..59]

millisecond

number

The milliseconds [0..999]

elapsed [const]

number

time in milliseconds since start was called

Methods

Return

Signature

Description

 

start()

Starts the 24 hour stopwatch.

 

restart()

restarts the stopwatch

boolean

isValid()

returns true if this object is valid.

start()

Starts the 24 hour stopwatch. Note that this object can at maximum count 24 hours.

restart()

Restarts the 24 hour stopwatch.

isValid()

isValid returns true if the timer countains a valid time.

Operators

Time::+ Time

Time::- Time

Time::<, <=, >, >=, == Time

Time::+Time / Time::-Time

Adds or subtracts time. Note that time will wrap at either 0 or 24 hours as it cannot give negative numbers or hours beyond 24. To go beyond 24 hours use the Date object and add to that.

Time Relational operators

The relational operators allow quick comparison between time objects.

Examples

local t1 = date.newTime(10,10)

local t2 = date.newTime(10,20)

local t3 = date.newTime(0,30)

 

print( t1 < t2 )

 

t1 = t1 + t3

 

print( t1 < t2 )

 

This will print

 

true

true

Related

Date Object

newTime

Availability

Lua