[Home] [Downloads] [Search] [Help/forum]



Calculates a time difference in seconds


n = os.difftime (t1, t2)


Returns the number of seconds from time t1 to time t2.

In other words, the result is t1 - t2.

tstart = os.time ()
-- do something lengthy here ..
tend = os.time ()
print (os.difftime (tend , tstart)) --> 3

When using MUSHclient (ie. this is not standard Lua) you can get better resolution by using GetInfo (which uses the Windows "high performance" timer), like this:

tstart = GetInfo (232)  -- get high-resolution timer value
-- do something lengthy here ..
tend = GetInfo (232)    
print (string.format ("Time taken = %1.3f seconds", tend - tstart))

See Also ...

Lua functions

os.clock - Amount of elapsed/CPU time used (depending on OS)
os.date - Formats a date/time string
os.execute - Executes an operating system command
os.exit - Attempts to terminate the process
os.getenv - Returns an operating system environment variable
os.remove - Deletes a file
os.rename - Renames a file
os.setlocale - Sets the current locale to the supplied locale
os.time - Returns the current time or calculates the time in seconds from a table
os.tmpname - Returns a name for a temporary file


Lua base functions
Lua bc (big number) functions
Lua bit manipulation functions
Lua coroutine functions
Lua debug functions
Lua io functions
Lua math functions
Lua os functions
Lua package functions
Lua PCRE regular expression functions
Lua script extensions
Lua string functions
Lua syntax
Lua table functions
Lua utilities
Scripting callbacks - plugins

(Help topic: lua=os.difftime)

Documentation contents page

Search ...

Enter a search string to find matching documentation.

Search for:   

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]