Skip to main content

time()

Returns the current date and time as elapsed seconds since midnight, 1 Jan 1970

Availability

Device + Agent

Returns

Integer

Description

This function returns the current date and time in the form of an integer representing the number of seconds that have elapsed since midnight on 1 January 1970. The value returned may be passed to the function date() to be converted into the current date and time, presented as a table.

If you are considering using time() to measure the duration of time that has elapsed between two events, you may wish to use the imp API’s hardware.millis() or hardware.micros() instead as these will deliver more precise timings.

Module-specific Notes

imp005

On the imp005, time() is only correct after connecting to the server.

Example Code