os.date

From Garry's Mod
Jump to: navigation, search
 os.date( )

Contents

Description

Returns the date/time as a formatted string or in a table.

Arguments

string format

The format string.

If this is equal to '*t' or '!*t' then this function will return a DateData structure, otherwise it will return a string.

If this starts with an '!', the returned data will use the UTC timezone rather than the local timezone.

See http://www.mkssoftware.com/docs/man3/strftime.3.asp for available format flags.

BUG

Not all flags are available on all operating systems and the result of using an invalid flag is undefined. This currently crashes the game on Windows. Most or all flags are available on OS X and Linux but considerably fewer are available on Windows. See http://msdn.microsoft.com/en-us/library/fe06s4ak.aspx for a list of available flags on Windows. Note that the # flags also crashes the game on Windows.

Issue Tracker: #329

Arguments

number time

Time to use for the format.

Returns

string

Formatted date

NOTE

This will be a DateData structure if the first argument equals to '*t' or '!*t'

Examples

Example

This will use the os.time() function, and return it in a friendly way. os.time() is useful for storing as a date stamp but needs this to make it readable.

local Timestamp = os.time()
local TimeString = os.date( "%H:%M:%S - %d/%m/%Y" , Timestamp )
print( "Timestamp:", Timestamp )
print( "TimeString:", TimeString )

Output:

Timestamp:	1569265508
TimeString:	19:05:09 - 23/09/2019
Personal tools
Navigation