Timestamps

Timestamps are provided by the via the timestamp function.

type_of() a timestamp returns "timestamp".

Built-in Functions

The following methods operate on timestamps.

FunctionParameter(s)Description
elapsed method and propertynonereturns the number of seconds since the timestamp
+ operatornumber of seconds to addreturns a new timestamp with a specified number of seconds added
+= operatornumber of seconds to addadds a specified number of seconds to the timestamp
- operatornumber of seconds to subtractreturns a new timestamp with a specified number of seconds subtracted
-= operatornumber of seconds to subtractsubtracts a specified number of seconds from the timestamp
- operator
  1. later timestamp
  2. earlier timestamp
returns the number of seconds between the two timestamps

The following time-related functions are also available.

FunctionParameter(s)Description
sleepnumber of seconds to sleepblocks the current thread for a specified number of seconds

Examples

let now = timestamp();

// Do some lengthy operation...

if now.elapsed > 30.0 {
    print("takes too long (over 30 seconds)!")
}